private void reLoadHost() { hostCacheDataFile = dataFileManager.getDataFile( ZABBIX_ID + "/" + ZABBIX_HOST ); ObjectMapper mapper = new ObjectMapper(); if ( hostCacheDataFile.exists() ) { try { String hosts = hostCacheDataFile.readString(); hostCache = mapper.readValue( hosts, ConcurrentHashMap.class ); } catch ( IOException e ) { e.printStackTrace(); logger.error( "read hosts cache from data file have a error:" + e ); } } }
private void reLoadHostGroup() { hostGroupCacheDataFile = dataFileManager.getDataFile( ZABBIX_ID + "/" + ZABBIX_HOSTGROUP ); ObjectMapper mapper = new ObjectMapper(); if ( hostGroupCacheDataFile.exists() ) { try { HashMap m = new HashMap( ); m.put( "test","123" ); mapper.writeValueAsString( m ); String hostGroups = hostGroupCacheDataFile.readString(); hostGroupCache = mapper.readValue( hostGroups, ConcurrentHashMap.class ); } catch ( IOException e ) { e.printStackTrace(); logger.error( "read hostGroup cache from data file have a error:" + e ); } } }
private void reLoadItem() { itemCacheDataFile = dataFileManager.getDataFile( ZABBIX_ID + "/" + ZABBIX_ITEM ); ObjectMapper mapper = new ObjectMapper(); if ( itemCacheDataFile.exists() ) { try { String items = itemCacheDataFile.readString(); itemCache = mapper.readValue( items, ConcurrentHashMap.class ); } catch ( IOException e ) { e.printStackTrace(); logger.error( "read items cache from data file have a error:" + e ); } } }
public DataFile getSetBackSettings( final StoreKey key ) { if ( !config.isEnabled() ) { return null; } final DataFile settingsXml = getSettingsXml( key ); return settingsXml == null || !settingsXml.exists() ? null : settingsXml; }
if ( lifecycleDir.exists() ) { final DataFile[] scripts = lifecycleDir.listFiles((pathname) ->
public boolean deleteStoreSettings( final ArtifactStore store ) throws SetBackDataException { if ( !config.isEnabled() ) { throw new SetBackDataException( "SetBack is disabled!" ); } final StoreKey key = store.getKey(); if ( StoreType.hosted == key.getType() ) { return false; } final DataFile settingsXml = getSettingsXml( key ); if ( settingsXml.exists() ) { try { settingsXml.delete( new ChangeSummary( ChangeSummary.SYSTEM_USER, "SETBACK: Deleting generated SetBack settings.xml for: " + store ) ); } catch ( final IOException e ) { throw new SetBackDataException( "Failed to delete SetBack settings.xml for: %s.\n at: %s\n Reason: %s", e, store, settingsXml, e.getMessage() ); } return true; } return false; }
private void store( final boolean skipIfExists, final ChangeSummary summary, final ArtifactStore... stores ) throws IndyDataException { for ( final ArtifactStore store : stores ) { final DataFile f = manager.getDataFile( INDY_STORE, store.getPackageType(), store.getType().singularEndpointName(), store.getName() + ".json" ); if ( skipIfExists && f.exists() ) { continue; } final DataFile d = f.getParent(); if ( !d.mkdirs() ) { throw new IndyDataException( "Cannot create storage directory: {} for definition: {}", d, store ); } try { final String json = serializer.writeValueAsString( store ); f.writeString( json, "UTF-8", summary ); logger.debug( "Persisted {} to disk at: {}\n{}", store, f, json ); } catch ( final IOException e ) { throw new IndyDataException( "Cannot write definition: {} to: {}. Reason: {}", e, store, f, e.getMessage() ); } } }
if ( settingsXml == null || !settingsXml.exists() )