id
stringlengths
7
14
text
stringlengths
1
106k
223551095_2243
@Transactional public HostConfigMapping merge(HostConfigMapping hostConfigMapping) { populateCache(); Long hostId = hostConfigMapping.getHostId(); if (hostId != null) { Set<HostConfigMapping> set; if (hostConfigMappingByHost.containsKey(hostId)) { set = hostConfigMappingByHost.get(hostId); } else { set = new HashSet<>(); hostConfigMappingByHost.put(hostId, set); } //Update object in set set.remove(hostConfigMapping); set.add(hostConfigMapping); entityManagerProvider.get().merge(buildHostConfigMappingEntity(hostConfigMapping)); } return hostConfigMapping; }
223551095_2244
@RequiresSession public Set<HostConfigMapping> findSelected(final long clusterId, Long hostId) { populateCache(); if (!hostConfigMappingByHost.containsKey(hostId)) return Collections.emptySet(); Set<HostConfigMapping> set = new HashSet<>(hostConfigMappingByHost.get(hostId)); CollectionUtils.filter(set, new Predicate() { @Override public boolean evaluate(Object arg0) { return ((HostConfigMapping) arg0).getClusterId().equals(clusterId) && ((HostConfigMapping) arg0).getSelected() > 0; } }); return set; }
223551095_2245
@RequiresSession public HostConfigMapping findSelectedByType(final long clusterId, Long hostId, final String type) { populateCache(); if (!hostConfigMappingByHost.containsKey(hostId)) return null; Set<HostConfigMapping> set = new HashSet<>(hostConfigMappingByHost.get(hostId)); HostConfigMapping result = (HostConfigMapping) CollectionUtils.find(set, new Predicate() { @Override public boolean evaluate(Object arg0) { return ((HostConfigMapping) arg0).getClusterId().equals(clusterId) && ((HostConfigMapping) arg0).getType().equals(type) && ((HostConfigMapping) arg0).getSelected() > 0; } }); return result; }
223551095_2246
@RequiresSession public List<TopologyRequestEntity> findByClusterId(long clusterId) { TypedQuery<TopologyRequestEntity> query = entityManagerProvider.get() .createNamedQuery("TopologyRequestEntity.findByClusterId", TopologyRequestEntity.class); query.setParameter("clusterId", clusterId); return daoUtils.selectList(query); }
223551095_2247
@Transactional public void removeAll(Long clusterId) { List<TopologyRequestEntity> clusterTopologyRequests = findByClusterId(clusterId); for (TopologyRequestEntity topologyRequestEntity: clusterTopologyRequests) remove(topologyRequestEntity); }
223551095_2248
@RequiresSession public UserEntity findUserByName(String userName) { TypedQuery<UserEntity> query = entityManagerProvider.get().createNamedQuery("userByName", UserEntity.class); query.setParameter("username", userName.toLowerCase()); try { return query.getSingleResult(); } catch (NoResultException e) { return null; } }
223551095_2251
@RequiresSession public List<UpgradeEntity> findUpgrades(long clusterId) { TypedQuery<UpgradeEntity> query = entityManagerProvider.get().createNamedQuery( "UpgradeEntity.findAllForCluster", UpgradeEntity.class); query.setParameter("clusterId", Long.valueOf(clusterId)); return daoUtils.selectList(query); }
223551095_2252
@RequiresSession public UpgradeEntity findUpgrade(long upgradeId) { TypedQuery<UpgradeEntity> query = entityManagerProvider.get().createNamedQuery( "UpgradeEntity.findUpgrade", UpgradeEntity.class); query.setParameter("upgradeId", Long.valueOf(upgradeId)); return daoUtils.selectSingle(query); }
223551095_2253
@RequiresSession public UpgradeEntity findLastUpgradeForCluster(long clusterId, Direction direction) { TypedQuery<UpgradeEntity> query = entityManagerProvider.get().createNamedQuery( "UpgradeEntity.findLatestForClusterInDirection", UpgradeEntity.class); query.setMaxResults(1); query.setParameter("clusterId", clusterId); query.setParameter("direction", direction); return daoUtils.selectSingle(query); }
223551095_2268
@RequiresSession public List<AlertHistoryEntity> findAll() { TypedQuery<AlertHistoryEntity> query = m_entityManagerProvider.get().createNamedQuery( "AlertHistoryEntity.findAll", AlertHistoryEntity.class); return m_daoUtils.selectList(query); }
223551095_2273
@RequiresSession public List<AlertHistoryEntity> findAll() { TypedQuery<AlertHistoryEntity> query = m_entityManagerProvider.get().createNamedQuery( "AlertHistoryEntity.findAll", AlertHistoryEntity.class); return m_daoUtils.selectList(query); }
223551095_2274
@RequiresSession public List<TopologyLogicalRequestEntity> findAll() { return daoUtils.selectAll(entityManagerProvider.get(), TopologyLogicalRequestEntity.class); }
223551095_2276
@RequiresSession public ServiceConfigEntity find(Long serviceConfigId) { return entityManagerProvider.get().find(ServiceConfigEntity.class, serviceConfigId); }
223551095_2277
@RequiresSession public ServiceConfigEntity findByServiceAndVersion(String serviceName, Long version) { TypedQuery<ServiceConfigEntity> query = entityManagerProvider.get(). createQuery("SELECT scv FROM ServiceConfigEntity scv " + "WHERE scv.serviceName=?1 AND scv.version=?2", ServiceConfigEntity.class); return daoUtils.selectOne(query, serviceName, version); }
223551095_2278
@RequiresSession public Long findNextServiceConfigVersion(long clusterId, String serviceName) { TypedQuery<Number> query = entityManagerProvider.get().createNamedQuery( "ServiceConfigEntity.findNextServiceConfigVersion", Number.class); query.setParameter("clusterId", clusterId); query.setParameter("serviceName", serviceName); return daoUtils.selectSingle(query).longValue(); }
223551095_2279
@RequiresSession public List<ServiceConfigEntity> getLastServiceConfigs(Long clusterId) { TypedQuery<ServiceConfigEntity> query = entityManagerProvider.get().createNamedQuery( "ServiceConfigEntity.findLatestServiceConfigsByCluster", ServiceConfigEntity.class); query.setParameter("clusterId", clusterId); return daoUtils.selectList(query); }
223551095_2280
@RequiresSession public List<ServiceConfigEntity> getLastServiceConfigsForService(Long clusterId, String serviceName) { TypedQuery<ServiceConfigEntity> query = entityManagerProvider.get().createNamedQuery( "ServiceConfigEntity.findLatestServiceConfigsByService", ServiceConfigEntity.class); query.setParameter("clusterId", clusterId); query.setParameter("serviceName", serviceName); return daoUtils.selectList(query); }
223551095_2281
@RequiresSession public ServiceConfigEntity getLastServiceConfig(Long clusterId, String serviceName) { TypedQuery<ServiceConfigEntity> query = entityManagerProvider.get(). createQuery("SELECT scv FROM ServiceConfigEntity scv " + "WHERE scv.clusterId = ?1 AND scv.serviceName = ?2 " + "ORDER BY scv.createTimestamp DESC", ServiceConfigEntity.class); return daoUtils.selectOne(query, clusterId, serviceName); }
223551095_2282
@RequiresSession public List<ServiceConfigEntity> getServiceConfigs(Long clusterId) { TypedQuery<ServiceConfigEntity> query = entityManagerProvider.get().createNamedQuery( "ServiceConfigEntity.findAll", ServiceConfigEntity.class); query.setParameter("clusterId", clusterId); return daoUtils.selectList(query); }
223551095_2283
@RequiresSession public List<ServiceConfigEntity> getServiceConfigsForServiceAndStack(Long clusterId, StackId stackId, String serviceName) { StackEntity stackEntity = stackDAO.find(stackId.getStackName(), stackId.getStackVersion()); TypedQuery<ServiceConfigEntity> query = entityManagerProvider.get().createNamedQuery( "ServiceConfigEntity.findAllServiceConfigsByStack", ServiceConfigEntity.class); query.setParameter("clusterId", clusterId); query.setParameter("stack", stackEntity); query.setParameter("serviceName", serviceName); return daoUtils.selectList(query); }
223551095_2292
@RequiresSession public AlertDefinitionEntity findByName(long clusterId, String definitionName) { TypedQuery<AlertDefinitionEntity> query = entityManagerProvider.get().createNamedQuery( "AlertDefinitionEntity.findByName", AlertDefinitionEntity.class); query.setParameter("clusterId", clusterId); query.setParameter("definitionName", definitionName); return daoUtils.selectSingle(query); }
223551095_2293
@RequiresSession public List<AlertDefinitionEntity> findAll() { TypedQuery<AlertDefinitionEntity> query = entityManagerProvider.get().createNamedQuery( "AlertDefinitionEntity.findAll", AlertDefinitionEntity.class); return daoUtils.selectList(query); }
223551095_2294
@RequiresSession public List<AlertDefinitionEntity> findAllEnabled(long clusterId) { TypedQuery<AlertDefinitionEntity> query = entityManagerProvider.get().createNamedQuery( "AlertDefinitionEntity.findAllEnabledInCluster", AlertDefinitionEntity.class); query.setParameter("clusterId", clusterId); return daoUtils.selectList(query); }
223551095_2295
@RequiresSession public AlertDefinitionEntity findById(long definitionId) { return entityManagerProvider.get().find(AlertDefinitionEntity.class, definitionId); }
223551095_2296
@RequiresSession public List<AlertDefinitionEntity> findByIds(List<Long> definitionIds) { TypedQuery<AlertDefinitionEntity> query = entityManagerProvider.get().createNamedQuery( "AlertDefinitionEntity.findByIds", AlertDefinitionEntity.class); query.setParameter("definitionIds", definitionIds); return daoUtils.selectList(query); }
223551095_2297
@RequiresSession public List<AlertDefinitionEntity> findByService(long clusterId, String serviceName) { TypedQuery<AlertDefinitionEntity> query = entityManagerProvider.get().createNamedQuery( "AlertDefinitionEntity.findByService", AlertDefinitionEntity.class); query.setParameter("clusterId", clusterId); query.setParameter("serviceName", serviceName); return daoUtils.selectList(query); }
223551095_2298
@RequiresSession public List<AlertDefinitionEntity> findByServiceComponent(long clusterId, String serviceName, String componentName) { if (null == serviceName || null == componentName) { return Collections.emptyList(); } TypedQuery<AlertDefinitionEntity> query = entityManagerProvider.get().createNamedQuery( "AlertDefinitionEntity.findByServiceAndComponent", AlertDefinitionEntity.class); query.setParameter("clusterId", clusterId); query.setParameter("serviceName", serviceName); query.setParameter("componentName", componentName); return daoUtils.selectList(query); }
223551095_2299
@RequiresSession public List<AlertDefinitionEntity> findAgentScoped(long clusterId) { TypedQuery<AlertDefinitionEntity> query = entityManagerProvider.get().createNamedQuery( "AlertDefinitionEntity.findByServiceAndComponent", AlertDefinitionEntity.class); query.setParameter("clusterId", clusterId); query.setParameter("serviceName", RootService.AMBARI.name()); query.setParameter("componentName", RootComponent.AMBARI_AGENT.name()); return daoUtils.selectList(query); }
223551095_2300
@Transactional public void refresh(AlertDefinitionEntity alertDefinition) { entityManagerProvider.get().refresh(alertDefinition); }
223551095_2301
@Transactional public void create(AlertDefinitionEntity alertDefinition) throws AmbariException { EntityManager entityManager = entityManagerProvider.get(); entityManager.persist(alertDefinition); AlertGroupEntity group = dispatchDao.findDefaultServiceGroup(alertDefinition.getClusterId(), alertDefinition.getServiceName()); if (null == group) { // create the default alert group for the new service; this MUST be done // before adding definitions so that they are properly added to the // default group String serviceName = alertDefinition.getServiceName(); group = dispatchDao.createDefaultGroup(alertDefinition.getClusterId(), serviceName); } group.addAlertDefinition(alertDefinition); AlertGroupsUpdateEvent alertGroupsUpdateEvent = new AlertGroupsUpdateEvent(Collections.singletonList( new AlertGroupUpdate(group)), UpdateEventType.UPDATE); STOMPUpdatePublisher.publish(alertGroupsUpdateEvent); dispatchDao.merge(group); // publish the alert definition registration AlertDefinition coerced = alertDefinitionFactory.coerce(alertDefinition); if (null != coerced) { AlertDefinitionRegistrationEvent event = new AlertDefinitionRegistrationEvent( alertDefinition.getClusterId(), coerced); eventPublisher.publish(event); } else { LOG.warn("Unable to broadcast alert registration event for {}", alertDefinition.getDefinitionName()); } entityManager.refresh(alertDefinition); }
223551095_2302
@Transactional public AlertDefinitionEntity merge(AlertDefinitionEntity alertDefinition) { AlertDefinitionEntity entity = entityManagerProvider.get().merge(alertDefinition); AlertDefinition definition = alertDefinitionFactory.coerce(entity); AlertDefinitionChangedEvent event = new AlertDefinitionChangedEvent( alertDefinition.getClusterId(), definition); eventPublisher.publish(event); return entity; }
223551095_2303
@Transactional public void remove(AlertDefinitionEntity alertDefinition) { dispatchDao.removeNoticeByDefinitionId(alertDefinition.getDefinitionId()); alertsDao.removeByDefinitionId(alertDefinition.getDefinitionId()); EntityManager entityManager = entityManagerProvider.get(); alertDefinition = findById(alertDefinition.getDefinitionId()); if (null != alertDefinition) { entityManager.remove(alertDefinition); // publish the alert definition removal AlertDefinition coerced = alertDefinitionFactory.coerce(alertDefinition); if (null != coerced) { AlertDefinitionDeleteEvent event = new AlertDefinitionDeleteEvent( alertDefinition.getClusterId(), coerced); eventPublisher.publish(event); } else { LOG.warn("Unable to broadcast alert removal event for {}", alertDefinition.getDefinitionName()); } } }
223551095_2305
@RequiresSession public List<StageEntity> findAll() { return daoUtils.selectAll(entityManagerProvider.get(), StageEntity.class); }
223551095_2306
@RequiresSession public List<StageEntity> findAll() { return daoUtils.selectAll(entityManagerProvider.get(), StageEntity.class); }
223551095_2307
@RequiresSession public AlertGroupEntity findGroupById(long groupId) { return entityManagerProvider.get().find(AlertGroupEntity.class, groupId); }
223551095_2308
@RequiresSession public List<AlertGroupEntity> findGroupsByDefinition( AlertDefinitionEntity definitionEntity) { TypedQuery<AlertGroupEntity> query = entityManagerProvider.get().createNamedQuery( "AlertGroupEntity.findByAssociatedDefinition", AlertGroupEntity.class); query.setParameter("alertDefinition", definitionEntity); query.setHint(QueryHints.REFRESH, HintValues.TRUE); return daoUtils.selectList(query); }
223551095_2309
@RequiresSession public AlertNoticeEntity findNoticeByUuid(String uuid) { TypedQuery<AlertNoticeEntity> query = entityManagerProvider.get().createNamedQuery( "AlertNoticeEntity.findByUuid", AlertNoticeEntity.class); query.setParameter("uuid", uuid); return daoUtils.selectOne(query); }
223551095_2310
@RequiresSession public List<AlertNoticeEntity> findAllNotices() { TypedQuery<AlertNoticeEntity> query = entityManagerProvider.get().createNamedQuery( "AlertNoticeEntity.findAll", AlertNoticeEntity.class); return daoUtils.selectList(query); }
223551095_2311
@RequiresSession public List<AlertNoticeEntity> findAllNotices() { TypedQuery<AlertNoticeEntity> query = entityManagerProvider.get().createNamedQuery( "AlertNoticeEntity.findAll", AlertNoticeEntity.class); return daoUtils.selectList(query); }
223551095_2312
@RequiresSession public List<AlertNoticeEntity> findAllNotices() { TypedQuery<AlertNoticeEntity> query = entityManagerProvider.get().createNamedQuery( "AlertNoticeEntity.findAll", AlertNoticeEntity.class); return daoUtils.selectList(query); }
223551095_2316
@RequiresSession public List<HostVersionEntity> findByHost(String hostName) { final TypedQuery<HostVersionEntity> query = entityManagerProvider.get() .createNamedQuery("hostVersionByHostname", HostVersionEntity.class); query.setParameter("hostName", hostName); return daoUtils.selectList(query); }
223551095_2317
@RequiresSession public List<HostVersionEntity> findByClusterStackAndVersion( String clusterName, StackId stackId, String version) { final TypedQuery<HostVersionEntity> query = entityManagerProvider.get().createNamedQuery("hostVersionByClusterAndStackAndVersion", HostVersionEntity.class); query.setParameter("clusterName", clusterName); query.setParameter("stackName", stackId.getStackName()); query.setParameter("stackVersion", stackId.getStackVersion()); query.setParameter("version", version); return daoUtils.selectList(query); }
223551095_2318
@RequiresSession public List<HostVersionEntity> findByClusterAndHost(String clusterName, String hostName) { final TypedQuery<HostVersionEntity> query = entityManagerProvider.get() .createNamedQuery("hostVersionByClusterAndHostname", HostVersionEntity.class); query.setParameter("clusterName", clusterName); query.setParameter("hostName", hostName); return daoUtils.selectList(query); }
223551095_2319
@RequiresSession public List<HostVersionEntity> findByCluster(String clusterName) { final TypedQuery<HostVersionEntity> query = entityManagerProvider.get() .createNamedQuery("findByCluster", HostVersionEntity.class); query.setParameter("clusterName", clusterName); return daoUtils.selectList(query); }
223551095_2320
@RequiresSession public List<HostVersionEntity> findByClusterHostAndState(String clusterName, String hostName, RepositoryVersionState state) { final TypedQuery<HostVersionEntity> query = entityManagerProvider.get() .createNamedQuery("hostVersionByClusterHostnameAndState", HostVersionEntity.class); query.setParameter("clusterName", clusterName); query.setParameter("hostName", hostName); query.setParameter("state", state); return daoUtils.selectList(query); }
223551095_2321
@RequiresSession public HostVersionEntity findByClusterStackVersionAndHost(String clusterName, StackId stackId, String version, String hostName) { final TypedQuery<HostVersionEntity> query = entityManagerProvider.get() .createNamedQuery("hostVersionByClusterStackVersionAndHostname", HostVersionEntity.class); query.setParameter("clusterName", clusterName); query.setParameter("stackName", stackId.getStackName()); query.setParameter("stackVersion", stackId.getStackVersion()); query.setParameter("version", version); query.setParameter("hostName", hostName); return daoUtils.selectSingle(query); }
223551095_2322
@Override @Transactional public void create(HostVersionEntity entity) throws IllegalArgumentException{ // check if repository version is not missing, to avoid NPE if (entity.getRepositoryVersion() == null) { throw new IllegalArgumentException("RepositoryVersion argument is not set for the entity"); } super.create(entity); entity.getRepositoryVersion().updateHostVersionEntityRelation(entity); }
223551095_2323
@Transactional public void remove(HostComponentDesiredStateEntity hostComponentDesiredStateEntity) { HostEntity hostEntity = hostComponentDesiredStateEntity.getHostEntity(); if (hostEntity == null) { throw new IllegalStateException(String.format("Missing hostEntity for host id %1d", hostComponentDesiredStateEntity.getHostId())); } hostEntity.removeHostComponentDesiredStateEntity(hostComponentDesiredStateEntity); entityManagerProvider.get().remove(hostComponentDesiredStateEntity); hostDAO.merge(hostEntity); }
223551095_2324
@Transactional public void remove(HostComponentStateEntity hostComponentStateEntity) { entityManagerProvider.get().remove(hostComponentStateEntity); }
223551095_2325
@RequiresSession public List<RequestEntity> findAll() { return daoUtils.selectAll(entityManagerProvider.get(), RequestEntity.class); }
223551095_2326
@RequiresSession public List<Long> findAllRequestIds(int limit, boolean ascending) { String sort = "ASC"; if (!ascending) { sort = "DESC"; } String sql = MessageFormat.format(REQUEST_IDS_SORTED_SQL, sort); TypedQuery<Long> query = entityManagerProvider.get().createQuery(sql, Long.class); query.setMaxResults(limit); return daoUtils.selectList(query); }
223551095_2327
@RequiresSession public RequestEntity findByPK(Long requestId) { return entityManagerProvider.get().find(RequestEntity.class, requestId); }
223551095_2344
@Override public DbType getDbType() { return dbType; }
223551095_2345
@Override public void alterColumn(String tableName, DBColumnInfo columnInfo) throws SQLException { //varchar extension only (derby limitation, but not too much for others), if (dbmsHelper.supportsColumnTypeChange()) { String statement = dbmsHelper.getAlterColumnStatement(tableName, columnInfo); executeQuery(statement); } else { //use addColumn: add_tmp-update-drop-rename for Derby DBColumnInfo columnInfoTmp = new DBColumnInfo( columnInfo.getName() + "_TMP", columnInfo.getType(), columnInfo.getLength()); String statement = dbmsHelper.getAddColumnStatement(tableName, columnInfoTmp); executeQuery(statement); updateTable(tableName, columnInfo, columnInfoTmp); dropColumn(tableName, columnInfo.getName()); renameColumn(tableName, columnInfoTmp.getName(), columnInfo); } if (isColumnNullable(tableName, columnInfo.getName()) != columnInfo.isNullable()) { setColumnNullable(tableName, columnInfo, columnInfo.isNullable()); } }
223551095_2346
@Override public void createTable(String tableName, List<DBColumnInfo> columnInfo, String... primaryKeyColumns) throws SQLException { // do nothing if the table already exists if (tableExists(tableName)) { return; } // guard against null PKs primaryKeyColumns = ArrayUtils.nullToEmpty(primaryKeyColumns); String query = dbmsHelper.getCreateTableStatement(tableName, columnInfo, Arrays.asList(primaryKeyColumns)); executeQuery(query); }
223551095_2347
@Override public void addFKConstraint(String tableName, String constraintName, String keyColumn, String referenceTableName, String referenceColumn, boolean ignoreFailure) throws SQLException { addFKConstraint(tableName, constraintName, new String[]{keyColumn}, referenceTableName, new String[]{referenceColumn}, false, ignoreFailure); }
223551095_2348
@Override public void addPKConstraint(String tableName, String constraintName, boolean ignoreErrors, String... columnName) throws SQLException { if (!tableHasPrimaryKey(tableName, null) && tableHasColumn(tableName, columnName)) { String query = dbmsHelper.getAddPrimaryKeyConstraintStatement(tableName, constraintName, columnName); executeQuery(query, ignoreErrors); } else { LOG.warn("Primary constraint {} not altered to table {} as column {} not present or constraint already exists", constraintName, tableName, columnName); } }
223551095_2349
@Override public void addColumn(String tableName, DBColumnInfo columnInfo) throws SQLException { if (tableHasColumn(tableName, columnInfo.getName())) { return; } DatabaseType databaseType = configuration.getDatabaseType(); switch (databaseType) { case ORACLE: { // capture the original null value and set the column to nullable if // there is a default value boolean originalNullable = columnInfo.isNullable(); if (columnInfo.getDefaultValue() != null) { columnInfo.setNullable(true); } String query = dbmsHelper.getAddColumnStatement(tableName, columnInfo); executeQuery(query); // update the column after it's been created with the default value and // then set the nullable field back to the specified value if (columnInfo.getDefaultValue() != null) { updateTable(tableName, columnInfo.getName(), columnInfo.getDefaultValue(), ""); // if the column wasn't originally nullable, then set that here if (!originalNullable) { setColumnNullable(tableName, columnInfo, originalNullable); } // finally, add the DEFAULT constraint to the table addDefaultConstraint(tableName, columnInfo); } break; } case DERBY: case MYSQL: case POSTGRES: case SQL_ANYWHERE: case SQL_SERVER: default: { // ToDo: getAddColumnStatement not supporting default clause for binary fields String query = dbmsHelper.getAddColumnStatement(tableName, columnInfo); executeQuery(query); break; } } }
223551095_2350
@Override public void updateTable(String tableName, DBColumnInfo columnNameFrom, DBColumnInfo columnNameTo) throws SQLException { LOG.info("Executing query: UPDATE TABLE " + tableName + " SET " + columnNameTo.getName() + "=" + columnNameFrom.getName()); String statement = "SELECT * FROM " + tableName; int typeFrom = getColumnType(tableName, columnNameFrom.getName()); int typeTo = getColumnType(tableName, columnNameTo.getName()); Statement dbStatement = null; ResultSet rs = null; try { dbStatement = getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); rs = dbStatement.executeQuery(statement); while (rs.next()) { convertUpdateData(rs, columnNameFrom, typeFrom, columnNameTo, typeTo); rs.updateRow(); } } finally { if (rs != null) { rs.close(); } if (dbStatement != null) { dbStatement.close(); } } }
223551095_2351
public String getCheckedForeignKey(String rawTableName, String rawForeignKeyName) throws SQLException { DatabaseMetaData metaData = getDatabaseMetaData(); String tableName = convertObjectName(rawTableName); String foreignKeyName = convertObjectName(rawForeignKeyName); try (ResultSet rs = metaData.getImportedKeys(null, dbSchema, tableName)) { while (rs.next()) { String foundName = rs.getString("FK_NAME"); if (StringUtils.equals(foreignKeyName, foundName)) { return foundName; } } } DatabaseType databaseType = configuration.getDatabaseType(); if (databaseType == DatabaseType.ORACLE) { try (PreparedStatement ps = getConnection().prepareStatement("SELECT constraint_name FROM user_constraints WHERE table_name = ? AND constraint_type = 'R' AND constraint_name = ?")) { ps.setString(1, tableName); ps.setString(2, foreignKeyName); try (ResultSet rs = ps.executeQuery()) { if (rs.next()) { return foreignKeyName; } } } } LOG.warn("FK {} not found for table {}", foreignKeyName, tableName); return null; }
223551095_2352
@Override public boolean tableExists(String tableName) throws SQLException { boolean result = false; DatabaseMetaData metaData = getDatabaseMetaData(); ResultSet res = metaData.getTables(null, dbSchema, convertObjectName(tableName), new String[]{"TABLE"}); if (res != null) { try { if (res.next()) { result = res.getString("TABLE_NAME") != null && res.getString("TABLE_NAME").equalsIgnoreCase(tableName); } if (res.next()) { throw new IllegalStateException( String.format("Request for table [%s] existing returned more than one results", tableName)); } } finally { res.close(); } } return result; }
223551095_2353
@Override public boolean tableExists(String tableName) throws SQLException { boolean result = false; DatabaseMetaData metaData = getDatabaseMetaData(); ResultSet res = metaData.getTables(null, dbSchema, convertObjectName(tableName), new String[]{"TABLE"}); if (res != null) { try { if (res.next()) { result = res.getString("TABLE_NAME") != null && res.getString("TABLE_NAME").equalsIgnoreCase(tableName); } if (res.next()) { throw new IllegalStateException( String.format("Request for table [%s] existing returned more than one results", tableName)); } } finally { res.close(); } } return result; }
223551095_2354
@Override public boolean tableHasColumn(String tableName, String columnName) throws SQLException { boolean result = false; DatabaseMetaData metaData = getDatabaseMetaData(); ResultSet rs = metaData.getColumns(null, dbSchema, convertObjectName(tableName), convertObjectName(columnName)); if (rs != null) { try { if (rs.next()) { result = rs.getString("COLUMN_NAME") != null && rs.getString("COLUMN_NAME").equalsIgnoreCase(columnName); } if (rs.next()) { throw new IllegalStateException( String.format("Request for column [%s] existing in table [%s] returned more than one results", columnName, tableName)); } } finally { rs.close(); } } return result; }
223551095_2355
@Override public boolean tableHasColumn(String tableName, String columnName) throws SQLException { boolean result = false; DatabaseMetaData metaData = getDatabaseMetaData(); ResultSet rs = metaData.getColumns(null, dbSchema, convertObjectName(tableName), convertObjectName(columnName)); if (rs != null) { try { if (rs.next()) { result = rs.getString("COLUMN_NAME") != null && rs.getString("COLUMN_NAME").equalsIgnoreCase(columnName); } if (rs.next()) { throw new IllegalStateException( String.format("Request for column [%s] existing in table [%s] returned more than one results", columnName, tableName)); } } finally { rs.close(); } } return result; }
223551095_2356
@Override public boolean tableHasColumn(String tableName, String columnName) throws SQLException { boolean result = false; DatabaseMetaData metaData = getDatabaseMetaData(); ResultSet rs = metaData.getColumns(null, dbSchema, convertObjectName(tableName), convertObjectName(columnName)); if (rs != null) { try { if (rs.next()) { result = rs.getString("COLUMN_NAME") != null && rs.getString("COLUMN_NAME").equalsIgnoreCase(columnName); } if (rs.next()) { throw new IllegalStateException( String.format("Request for column [%s] existing in table [%s] returned more than one results", columnName, tableName)); } } finally { rs.close(); } } return result; }
223551095_2357
@Override public void renameColumn(String tableName, String oldColumnName, DBColumnInfo columnInfo) throws SQLException { //it is mandatory to specify type in column change clause for mysql String renameColumnStatement = dbmsHelper.getRenameColumnStatement(tableName, oldColumnName, columnInfo); executeQuery(renameColumnStatement); }
223551095_2358
@Override public int getColumnType(String tableName, String columnName) throws SQLException { // We doesn't require any actual result except metadata, so WHERE clause shouldn't match int res; String query; Statement statement = null; ResultSet rs = null; ResultSetMetaData rsmd = null; try { query = String.format("SELECT %s FROM %s WHERE 1=2", columnName, convertObjectName(tableName)); statement = getConnection().createStatement(); rs = statement.executeQuery(query); rsmd = rs.getMetaData(); res = rsmd.getColumnType(1); } finally { if (rs != null){ rs.close(); } if (statement != null) { statement.close(); } } return res; }
223551095_2359
@Override public void moveColumnToAnotherTable(String sourceTableName, DBColumnInfo sourceColumn, String sourceIDFieldName, String targetTableName, DBColumnInfo targetColumn, String targetIDFieldName, Object initialValue) throws SQLException { if (tableHasColumn(sourceTableName, sourceIDFieldName) && tableHasColumn(sourceTableName, sourceColumn.getName()) && tableHasColumn(targetTableName, targetIDFieldName) ) { final String moveSQL = dbmsHelper.getCopyColumnToAnotherTableStatement(sourceTableName, sourceColumn.getName(), sourceIDFieldName, targetTableName, targetColumn.getName(),targetIDFieldName); final boolean isTargetColumnNullable = targetColumn.isNullable(); targetColumn.setNullable(true); // setting column nullable by default to move rows with null addColumn(targetTableName, targetColumn); executeUpdate(moveSQL, false); if (initialValue != null) { String updateSQL = dbmsHelper.getColumnUpdateStatementWhereColumnIsNull(convertObjectName(targetTableName), convertObjectName(targetColumn.getName()), convertObjectName(targetColumn.getName())); executePreparedUpdate(updateSQL, initialValue); } if (!isTargetColumnNullable) { setColumnNullable(targetTableName, targetColumn.getName(), false); } dropColumn(sourceTableName, sourceColumn.getName()); } }
223551095_2360
@Override public void copyColumnToAnotherTable(String sourceTableName, DBColumnInfo sourceColumn, String sourceIDFieldName1, String sourceIDFieldName2, String sourceIDFieldName3, String targetTableName, DBColumnInfo targetColumn, String targetIDFieldName1, String targetIDFieldName2, String targetIDFieldName3, String sourceConditionFieldName, String condition, Object initialValue) throws SQLException { if (tableHasColumn(sourceTableName, sourceIDFieldName1) && tableHasColumn(sourceTableName, sourceIDFieldName2) && tableHasColumn(sourceTableName, sourceIDFieldName3) && tableHasColumn(sourceTableName, sourceColumn.getName()) && tableHasColumn(sourceTableName, sourceConditionFieldName) && tableHasColumn(targetTableName, targetIDFieldName1) && tableHasColumn(targetTableName, targetIDFieldName2) && tableHasColumn(targetTableName, targetIDFieldName3) ) { final String moveSQL = dbmsHelper.getCopyColumnToAnotherTableStatement(sourceTableName, sourceColumn.getName(), sourceIDFieldName1, sourceIDFieldName2, sourceIDFieldName3, targetTableName, targetColumn.getName(), targetIDFieldName1, targetIDFieldName2, targetIDFieldName3, sourceConditionFieldName, condition); final boolean isTargetColumnNullable = targetColumn.isNullable(); targetColumn.setNullable(true); // setting column nullable by default to move rows with null addColumn(targetTableName, targetColumn); executeUpdate(moveSQL, false); if (initialValue != null) { String updateSQL = dbmsHelper.getColumnUpdateStatementWhereColumnIsNull(convertObjectName(targetTableName), convertObjectName(targetColumn.getName()), convertObjectName(targetColumn.getName())); executePreparedUpdate(updateSQL, initialValue); } if (!isTargetColumnNullable) { setColumnNullable(targetTableName, targetColumn.getName(), false); } } }
223551095_2361
@Override public List<Integer> getIntColumnValues(String tableName, String columnName, String[] conditionColumnNames, String[] values, boolean ignoreFailure) throws SQLException { return executeQuery(tableName, new String[]{columnName}, conditionColumnNames, values, ignoreFailure, new ResultGetter<List<Integer>>() { private List<Integer> results = new ArrayList<>(); @Override public void collect(ResultSet resultSet) throws SQLException { results.add(resultSet.getInt(1)); } @Override public List<Integer> getResult() { return results; } }); }
223551095_2362
private static Class<?> fromSqlTypeToClass(int type) { switch (type) { case Types.VARCHAR: case Types.CHAR: case Types.LONGVARCHAR: return String.class; case Types.NUMERIC: case Types.DECIMAL: return BigDecimal.class; case Types.BIT: return Boolean.class; case Types.TINYINT: return Byte.class; case Types.SMALLINT: return Short.class; case Types.INTEGER: return Integer.class; case Types.BIGINT: return Long.class; case Types.FLOAT: case Types.REAL: return Float.class; case Types.DOUBLE: return Double.class; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: return Byte[].class; case Types.DATE: return java.sql.Date.class; case Types.TIME: return java.sql.Timestamp.class; default: return null; } }
223551095_2363
protected String buildQuery(String tableName, String[] requestedColumnNames, String[] conditionColumnNames, String[] conditionValues) throws SQLException { if (!tableExists(tableName)) { throw new IllegalArgumentException(String.format("%s table does not exist", tableName)); } StringBuilder builder = new StringBuilder(); builder.append("SELECT "); // Append the requested column names: if ((requestedColumnNames == null) || (requestedColumnNames.length == 0)) { throw new IllegalArgumentException("no columns for the select have been set"); } for (String name : requestedColumnNames) { if (!tableHasColumn(tableName, name)) { throw new IllegalArgumentException(String.format("%s table does not contain %s column", tableName, name)); } } builder.append(requestedColumnNames[0]); for (int i = 1; i < requestedColumnNames.length; i++) { builder.append(", ").append(requestedColumnNames[1]); } // Append the source table builder.append(" FROM ").append(tableName); // Add the WHERE clause using the conditionColumnNames and the conditionValues if (conditionColumnNames != null && conditionColumnNames.length > 0) { for (String name : conditionColumnNames) { if (!tableHasColumn(tableName, name)) { throw new IllegalArgumentException(String.format("%s table does not contain %s column", tableName, name)); } } if (conditionColumnNames.length != conditionValues.length) { throw new IllegalArgumentException("number of columns should be equal to number of values"); } builder.append(" WHERE ").append(conditionColumnNames[0]).append("='").append(conditionValues[0]).append("'"); for (int i = 1; i < conditionColumnNames.length; i++) { builder.append(" AND ").append(conditionColumnNames[i]).append("='").append(conditionValues[i]).append("'"); } } return builder.toString(); }
223551095_2364
private String escapeParameter(Object value) { return escapeParameter(value, databasePlatform); }
223551095_2365
private String escapeParameter(Object value) { return escapeParameter(value, databasePlatform); }
223551095_2366
private String escapeParameter(Object value) { return escapeParameter(value, databasePlatform); }
223551095_2367
void updateHostsInConfigurations() throws AmbariException { ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class); AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); if (clusters != null) { // going through all clusters with host pairs from file for (Map.Entry<String, Map<String,String>> clusterHosts : hostChangesFileMap.entrySet()) { boolean hostConfigsUpdated = false; String clusterName = clusterHosts.getKey(); ClusterEntity clusterEntity = clusterDAO.findByName(clusterName); Cluster cluster = clusters.getCluster(clusterName); Map<String, String> hostMapping = clusterHosts.getValue(); List<String> currentHostNames = new ArrayList<>(); String updatedPropertyValue; for (Map.Entry<String, String> hostPair : hostMapping.entrySet()) { currentHostNames.add(hostPair.getKey()); } //****************************** if (clusterEntity != null) { Collection<ClusterConfigEntity> clusterConfigEntities = clusterEntity.getClusterConfigEntities(); boolean configUpdated; // going through all cluster configs and update property values ConfigFactory configFactory = injector.getInstance(ConfigFactory.class); for (ClusterConfigEntity clusterConfigEntity : clusterConfigEntities) { Config config = configFactory.createExisting(cluster, clusterConfigEntity); configUpdated = false; for (Map.Entry<String,String> property : config.getProperties().entrySet()) { updatedPropertyValue = replaceHosts(property.getValue(), currentHostNames, hostMapping); if (updatedPropertyValue != null) { Map<String,String> propertiesWithUpdates = config.getProperties(); propertiesWithUpdates.put(property.getKey(), updatedPropertyValue); config.setProperties(propertiesWithUpdates); configUpdated = true; } } if (configUpdated) { hostConfigsUpdated = true; config.save(); } } } if (hostConfigsUpdated) { AgentConfigsHolder agentConfigsHolder = injector.getInstance(AgentConfigsHolder.class); agentConfigsHolder.updateData(cluster.getClusterId(), currentHostNames.stream() .map(hm -> cluster.getHost(hm).getHostId()).collect(Collectors.toList())); } //****************************** } } }
223551095_2369
void updateHostsForAlertsInDB() { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); AlertsDAO alertsDAO = injector.getInstance(AlertsDAO.class); AlertDefinitionDAO alertDefinitionDAO = injector.getInstance(AlertDefinitionDAO.class); Clusters clusters = ambariManagementController.getClusters(); if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); if (clusterMap != null) { for (Map.Entry<String, Map<String,String>> clusterHosts : hostChangesFileMap.entrySet()) { List<String> currentHostNames = new ArrayList<>(); Map<String, String> hostMapping = clusterHosts.getValue(); Long clusterId = clusterMap.get(clusterHosts.getKey()).getClusterId(); for (Map.Entry<String, String> hostPair : hostMapping.entrySet()) { currentHostNames.add(hostPair.getKey()); } List<AlertCurrentEntity> currentEntities = alertsDAO.findCurrentByCluster(clusterId); for (AlertCurrentEntity alertCurrentEntity : currentEntities) { AlertHistoryEntity alertHistoryEntity = alertCurrentEntity.getAlertHistory(); if (currentHostNames.contains(alertHistoryEntity.getHostName())) { alertHistoryEntity.setHostName(hostMapping.get(alertHistoryEntity.getHostName())); alertsDAO.merge(alertHistoryEntity); } } List<AlertDefinitionEntity> alertDefinitionEntities = alertDefinitionDAO.findAll(clusterId); for (AlertDefinitionEntity alertDefinitionEntity : alertDefinitionEntities) { alertDefinitionEntity.setHash(UUID.randomUUID().toString()); alertDefinitionDAO.merge(alertDefinitionEntity); } } } } }
223551095_2373
public synchronized void useMetrics(List<MetricData> metricsList) { if (!isMetricsEnabled) { return; } LOG.info("useMetrics() metrics.size=" + metricsList.size()); long currMS = System.currentTimeMillis(); gatherMetrics(metricsList, currMS); publishMetrics(currMS); }
223551095_2374
public synchronized void useMetrics(List<MetricData> metricsList) { if (!isMetricsEnabled) { return; } LOG.info("useMetrics() metrics.size=" + metricsList.size()); long currMS = System.currentTimeMillis(); gatherMetrics(metricsList, currMS); publishMetrics(currMS); }
223551095_2376
@Override public void apply(String inputStr, InputMarker inputMarker) throws Exception { Map<String, Object> jsonMap = null; try { jsonMap = LogFeederUtil.toJSONObject(inputStr); } catch (Exception e) { LOG.error(e.getLocalizedMessage()); throw new LogFeederException("Json parsing failed for inputstr = " + inputStr ,e.getCause()); } Double lineNumberD = (Double) jsonMap.get("line_number"); if (lineNumberD != null) { long lineNumber = lineNumberD.longValue(); jsonMap.put("line_number", lineNumber); } String timeStampStr = (String) jsonMap.get("logtime"); if (timeStampStr != null && !timeStampStr.isEmpty()) { String logtime = DateUtil.getDate(timeStampStr); jsonMap.put("logtime", logtime); jsonMap.put(LogFeederConstants.IN_MEMORY_TIMESTAMP, Long.parseLong(timeStampStr)); } super.apply(jsonMap, inputMarker); }
223551095_2377
@Override public void apply(String inputStr, InputMarker inputMarker) throws Exception { Map<String, Object> jsonMap = null; try { jsonMap = LogFeederUtil.toJSONObject(inputStr); } catch (Exception e) { LOG.error(e.getLocalizedMessage()); throw new LogFeederException("Json parsing failed for inputstr = " + inputStr ,e.getCause()); } Double lineNumberD = (Double) jsonMap.get("line_number"); if (lineNumberD != null) { long lineNumber = lineNumberD.longValue(); jsonMap.put("line_number", lineNumber); } String timeStampStr = (String) jsonMap.get("logtime"); if (timeStampStr != null && !timeStampStr.isEmpty()) { String logtime = DateUtil.getDate(timeStampStr); jsonMap.put("logtime", logtime); jsonMap.put(LogFeederConstants.IN_MEMORY_TIMESTAMP, Long.parseLong(timeStampStr)); } super.apply(jsonMap, inputMarker); }
223551095_2378
@Override public void apply(String inputStr, InputMarker inputMarker) throws Exception { Map<String, Object> jsonMap = null; try { jsonMap = LogFeederUtil.toJSONObject(inputStr); } catch (Exception e) { LOG.error(e.getLocalizedMessage()); throw new LogFeederException("Json parsing failed for inputstr = " + inputStr ,e.getCause()); } Double lineNumberD = (Double) jsonMap.get("line_number"); if (lineNumberD != null) { long lineNumber = lineNumberD.longValue(); jsonMap.put("line_number", lineNumber); } String timeStampStr = (String) jsonMap.get("logtime"); if (timeStampStr != null && !timeStampStr.isEmpty()) { String logtime = DateUtil.getDate(timeStampStr); jsonMap.put("logtime", logtime); jsonMap.put(LogFeederConstants.IN_MEMORY_TIMESTAMP, Long.parseLong(timeStampStr)); } super.apply(jsonMap, inputMarker); }
223551095_2379
@Override public void apply(String inputStr, InputMarker inputMarker) throws Exception { Map<String, Object> jsonMap = null; try { jsonMap = LogFeederUtil.toJSONObject(inputStr); } catch (Exception e) { LOG.error(e.getLocalizedMessage()); throw new LogFeederException("Json parsing failed for inputstr = " + inputStr ,e.getCause()); } Double lineNumberD = (Double) jsonMap.get("line_number"); if (lineNumberD != null) { long lineNumber = lineNumberD.longValue(); jsonMap.put("line_number", lineNumber); } String timeStampStr = (String) jsonMap.get("logtime"); if (timeStampStr != null && !timeStampStr.isEmpty()) { String logtime = DateUtil.getDate(timeStampStr); jsonMap.put("logtime", logtime); jsonMap.put(LogFeederConstants.IN_MEMORY_TIMESTAMP, Long.parseLong(timeStampStr)); } super.apply(jsonMap, inputMarker); }
223551095_2380
@Override public boolean init(String inputDesc, String fieldName, String mapClassCode, MapFieldDescriptor mapFieldDescriptor) { init(inputDesc, fieldName, mapClassCode); copyName = ((MapFieldCopyDescriptor)mapFieldDescriptor).getCopyName(); if (StringUtils.isEmpty(copyName)) { LOG.fatal("Map copy name is empty."); return false; } return true; }
223551095_2381
@Override public boolean init(String inputDesc, String fieldName, String mapClassCode, MapFieldDescriptor mapFieldDescriptor) { init(inputDesc, fieldName, mapClassCode); pattern = ((MapAnonymizeDescriptor)mapFieldDescriptor).getPattern(); if (StringUtils.isEmpty(pattern)) { LOG.fatal("pattern is empty."); return false; } patternParts = Splitter.on("<hide>").omitEmptyStrings().split(pattern); hideChar = CharUtils.toChar(((MapAnonymizeDescriptor)mapFieldDescriptor).getHideChar(), DEFAULT_HIDE_CHAR); return true; }
223551095_2382
@Override public boolean init(String inputDesc, String fieldName, String mapClassCode, MapFieldDescriptor mapFieldDescriptor) { init(inputDesc, fieldName, mapClassCode); String targetDateFormat = ((MapDateDescriptor)mapFieldDescriptor).getTargetDatePattern(); String srcDateFormat = ((MapDateDescriptor)mapFieldDescriptor).getSourceDatePattern(); if (StringUtils.isEmpty(targetDateFormat)) { LOG.fatal("Date format for map is empty. " + this); } else { LOG.info("Date mapper format is " + targetDateFormat); if (targetDateFormat.equalsIgnoreCase("epoch")) { isEpoch = true; return true; } else { try { targetDateFormatter = FastDateFormat.getInstance(targetDateFormat); if (!StringUtils.isEmpty(srcDateFormat)) { srcDateFormatter = FastDateFormat.getInstance(srcDateFormat); } return true; } catch (Throwable ex) { LOG.fatal("Error creating date format. format=" + targetDateFormat + ". " + this.toString()); } } } return false; }
223551095_2383
@Override public boolean init(String inputDesc, String fieldName, String mapClassCode, MapFieldDescriptor mapFieldDescriptor) { init(inputDesc, fieldName, mapClassCode); String targetDateFormat = ((MapDateDescriptor)mapFieldDescriptor).getTargetDatePattern(); String srcDateFormat = ((MapDateDescriptor)mapFieldDescriptor).getSourceDatePattern(); if (StringUtils.isEmpty(targetDateFormat)) { LOG.fatal("Date format for map is empty. " + this); } else { LOG.info("Date mapper format is " + targetDateFormat); if (targetDateFormat.equalsIgnoreCase("epoch")) { isEpoch = true; return true; } else { try { targetDateFormatter = FastDateFormat.getInstance(targetDateFormat); if (!StringUtils.isEmpty(srcDateFormat)) { srcDateFormatter = FastDateFormat.getInstance(srcDateFormat); } return true; } catch (Throwable ex) { LOG.fatal("Error creating date format. format=" + targetDateFormat + ". " + this.toString()); } } } return false; }
223551095_2384
@Override public boolean init(String inputDesc, String fieldName, String mapClassCode, MapFieldDescriptor mapFieldDescriptor) { init(inputDesc, fieldName, mapClassCode); prevValue = ((MapFieldValueDescriptor)mapFieldDescriptor).getPreValue(); newValue = ((MapFieldValueDescriptor)mapFieldDescriptor).getPostValue();; if (StringUtils.isEmpty(newValue)) { LOG.fatal("Map field value is empty."); return false; } return true; }
223551095_2385
@Override public boolean init(String inputDesc, String fieldName, String mapClassCode, MapFieldDescriptor mapFieldDescriptor) { init(inputDesc, fieldName, mapClassCode); newValue = ((MapFieldNameDescriptor)mapFieldDescriptor).getNewFieldName(); if (StringUtils.isEmpty(newValue)) { LOG.fatal("Map field value is empty."); return false; } return true; }
223551095_2390
public Boolean apply(Map<String, Object> lineMap, Input input) { boolean isLogFilteredOut = false; LRUCache inputLruCache = input.getCache(); if (inputLruCache != null && "service".equals(input.getInputDescriptor().getRowtype())) { String logMessage = (String) lineMap.get(input.getCacheKeyField()); Long timestamp = null; if (lineMap.containsKey((LogFeederConstants.IN_MEMORY_TIMESTAMP))) { timestamp = (Long) lineMap.get(LogFeederConstants.IN_MEMORY_TIMESTAMP); } if (logMessage != null && timestamp != null) { isLogFilteredOut = !inputLruCache.isEntryReplaceable(logMessage, timestamp); if (!isLogFilteredOut) { inputLruCache.put(logMessage, timestamp); } else { LOG.debug("Log line filtered out: {} (file: {}, dedupInterval: {}, lastDedupEnabled: {})", logMessage, inputLruCache.getFileName(), inputLruCache.getDedupInterval(), inputLruCache.isLastDedupEnabled()); } } } if (lineMap.containsKey(LogFeederConstants.IN_MEMORY_TIMESTAMP)) { lineMap.remove(LogFeederConstants.IN_MEMORY_TIMESTAMP); } return isLogFilteredOut; }
223551095_2391
public Boolean apply(Map<String, Object> lineMap, Input input) { boolean isLogFilteredOut = false; LRUCache inputLruCache = input.getCache(); if (inputLruCache != null && "service".equals(input.getInputDescriptor().getRowtype())) { String logMessage = (String) lineMap.get(input.getCacheKeyField()); Long timestamp = null; if (lineMap.containsKey((LogFeederConstants.IN_MEMORY_TIMESTAMP))) { timestamp = (Long) lineMap.get(LogFeederConstants.IN_MEMORY_TIMESTAMP); } if (logMessage != null && timestamp != null) { isLogFilteredOut = !inputLruCache.isEntryReplaceable(logMessage, timestamp); if (!isLogFilteredOut) { inputLruCache.put(logMessage, timestamp); } else { LOG.debug("Log line filtered out: {} (file: {}, dedupInterval: {}, lastDedupEnabled: {})", logMessage, inputLruCache.getFileName(), inputLruCache.getDedupInterval(), inputLruCache.isLastDedupEnabled()); } } } if (lineMap.containsKey(LogFeederConstants.IN_MEMORY_TIMESTAMP)) { lineMap.remove(LogFeederConstants.IN_MEMORY_TIMESTAMP); } return isLogFilteredOut; }
223551095_2392
public Boolean apply(Map<String, Object> lineMap, Input input) { boolean isLogFilteredOut = false; LRUCache inputLruCache = input.getCache(); if (inputLruCache != null && "service".equals(input.getInputDescriptor().getRowtype())) { String logMessage = (String) lineMap.get(input.getCacheKeyField()); Long timestamp = null; if (lineMap.containsKey((LogFeederConstants.IN_MEMORY_TIMESTAMP))) { timestamp = (Long) lineMap.get(LogFeederConstants.IN_MEMORY_TIMESTAMP); } if (logMessage != null && timestamp != null) { isLogFilteredOut = !inputLruCache.isEntryReplaceable(logMessage, timestamp); if (!isLogFilteredOut) { inputLruCache.put(logMessage, timestamp); } else { LOG.debug("Log line filtered out: {} (file: {}, dedupInterval: {}, lastDedupEnabled: {})", logMessage, inputLruCache.getFileName(), inputLruCache.getDedupInterval(), inputLruCache.isLastDedupEnabled()); } } } if (lineMap.containsKey(LogFeederConstants.IN_MEMORY_TIMESTAMP)) { lineMap.remove(LogFeederConstants.IN_MEMORY_TIMESTAMP); } return isLogFilteredOut; }
223551095_2393
public Boolean apply(Map<String, Object> lineMap, Input input) { boolean isLogFilteredOut = false; LRUCache inputLruCache = input.getCache(); if (inputLruCache != null && "service".equals(input.getInputDescriptor().getRowtype())) { String logMessage = (String) lineMap.get(input.getCacheKeyField()); Long timestamp = null; if (lineMap.containsKey((LogFeederConstants.IN_MEMORY_TIMESTAMP))) { timestamp = (Long) lineMap.get(LogFeederConstants.IN_MEMORY_TIMESTAMP); } if (logMessage != null && timestamp != null) { isLogFilteredOut = !inputLruCache.isEntryReplaceable(logMessage, timestamp); if (!isLogFilteredOut) { inputLruCache.put(logMessage, timestamp); } else { LOG.debug("Log line filtered out: {} (file: {}, dedupInterval: {}, lastDedupEnabled: {})", logMessage, inputLruCache.getFileName(), inputLruCache.getDedupInterval(), inputLruCache.isLastDedupEnabled()); } } } if (lineMap.containsKey(LogFeederConstants.IN_MEMORY_TIMESTAMP)) { lineMap.remove(LogFeederConstants.IN_MEMORY_TIMESTAMP); } return isLogFilteredOut; }
223551095_2394
public Boolean apply(Map<String, Object> lineMap, Input input) { boolean isLogFilteredOut = false; LRUCache inputLruCache = input.getCache(); if (inputLruCache != null && "service".equals(input.getInputDescriptor().getRowtype())) { String logMessage = (String) lineMap.get(input.getCacheKeyField()); Long timestamp = null; if (lineMap.containsKey((LogFeederConstants.IN_MEMORY_TIMESTAMP))) { timestamp = (Long) lineMap.get(LogFeederConstants.IN_MEMORY_TIMESTAMP); } if (logMessage != null && timestamp != null) { isLogFilteredOut = !inputLruCache.isEntryReplaceable(logMessage, timestamp); if (!isLogFilteredOut) { inputLruCache.put(logMessage, timestamp); } else { LOG.debug("Log line filtered out: {} (file: {}, dedupInterval: {}, lastDedupEnabled: {})", logMessage, inputLruCache.getFileName(), inputLruCache.getDedupInterval(), inputLruCache.isLastDedupEnabled()); } } } if (lineMap.containsKey(LogFeederConstants.IN_MEMORY_TIMESTAMP)) { lineMap.remove(LogFeederConstants.IN_MEMORY_TIMESTAMP); } return isLogFilteredOut; }
223551095_2395
public Boolean apply(Map<String, Object> lineMap, Input input) { boolean isLogFilteredOut = false; LRUCache inputLruCache = input.getCache(); if (inputLruCache != null && "service".equals(input.getInputDescriptor().getRowtype())) { String logMessage = (String) lineMap.get(input.getCacheKeyField()); Long timestamp = null; if (lineMap.containsKey((LogFeederConstants.IN_MEMORY_TIMESTAMP))) { timestamp = (Long) lineMap.get(LogFeederConstants.IN_MEMORY_TIMESTAMP); } if (logMessage != null && timestamp != null) { isLogFilteredOut = !inputLruCache.isEntryReplaceable(logMessage, timestamp); if (!isLogFilteredOut) { inputLruCache.put(logMessage, timestamp); } else { LOG.debug("Log line filtered out: {} (file: {}, dedupInterval: {}, lastDedupEnabled: {})", logMessage, inputLruCache.getFileName(), inputLruCache.getDedupInterval(), inputLruCache.isLastDedupEnabled()); } } } if (lineMap.containsKey(LogFeederConstants.IN_MEMORY_TIMESTAMP)) { lineMap.remove(LogFeederConstants.IN_MEMORY_TIMESTAMP); } return isLogFilteredOut; }
223551095_2396
public Boolean apply(Map<String, Object> lineMap, Input input) { boolean isLogFilteredOut = false; LRUCache inputLruCache = input.getCache(); if (inputLruCache != null && "service".equals(input.getInputDescriptor().getRowtype())) { String logMessage = (String) lineMap.get(input.getCacheKeyField()); Long timestamp = null; if (lineMap.containsKey((LogFeederConstants.IN_MEMORY_TIMESTAMP))) { timestamp = (Long) lineMap.get(LogFeederConstants.IN_MEMORY_TIMESTAMP); } if (logMessage != null && timestamp != null) { isLogFilteredOut = !inputLruCache.isEntryReplaceable(logMessage, timestamp); if (!isLogFilteredOut) { inputLruCache.put(logMessage, timestamp); } else { LOG.debug("Log line filtered out: {} (file: {}, dedupInterval: {}, lastDedupEnabled: {})", logMessage, inputLruCache.getFileName(), inputLruCache.getDedupInterval(), inputLruCache.isLastDedupEnabled()); } } } if (lineMap.containsKey(LogFeederConstants.IN_MEMORY_TIMESTAMP)) { lineMap.remove(LogFeederConstants.IN_MEMORY_TIMESTAMP); } return isLogFilteredOut; }
223551095_2401
@Override public void init(LogFeederProps logFeederProps) throws Exception { this.logFeederProps = logFeederProps; Properties props = initProperties(); producer = creteKafkaProducer(props); createKafkaRetryThread(); }
223551095_2402
@Override public void init(LogFeederProps logFeederProps) throws Exception { this.logFeederProps = logFeederProps; Properties props = initProperties(); producer = creteKafkaProducer(props); createKafkaRetryThread(); }
223551095_2409
public static LogSearchConfigServer createLogSearchConfigServer(Map<String, String> properties, Class<? extends LogSearchConfigServer> defaultClass, boolean init) throws Exception { try { LogSearchConfigServer logSearchConfig = null; String configClassName = properties.get("logsearch.config.server.class"); if (configClassName != null && !"".equals(configClassName.trim())) { Class<?> clazz = Class.forName(configClassName); if (LogSearchConfigServer.class.isAssignableFrom(clazz)) { logSearchConfig = (LogSearchConfigServer) clazz.newInstance(); } else { throw new IllegalArgumentException("Class " + configClassName + " does not implement the interface " + LogSearchConfigServer.class.getName()); } } else { logSearchConfig = defaultClass.newInstance(); } if (init) { logSearchConfig.init(properties); } return logSearchConfig; } catch (Exception e) { LOG.error("Could not initialize logsearch config.", e); throw e; } }
223551095_2410
public static LogSearchConfigServer createLogSearchConfigServer(Map<String, String> properties, Class<? extends LogSearchConfigServer> defaultClass, boolean init) throws Exception { try { LogSearchConfigServer logSearchConfig = null; String configClassName = properties.get("logsearch.config.server.class"); if (configClassName != null && !"".equals(configClassName.trim())) { Class<?> clazz = Class.forName(configClassName); if (LogSearchConfigServer.class.isAssignableFrom(clazz)) { logSearchConfig = (LogSearchConfigServer) clazz.newInstance(); } else { throw new IllegalArgumentException("Class " + configClassName + " does not implement the interface " + LogSearchConfigServer.class.getName()); } } else { logSearchConfig = defaultClass.newInstance(); } if (init) { logSearchConfig.init(properties); } return logSearchConfig; } catch (Exception e) { LOG.error("Could not initialize logsearch config.", e); throw e; } }