Class BaseFileResourceModelSource
- java.lang.Object
-
- com.dtolabs.rundeck.core.resources.BaseFileResourceModelSource
-
- All Implemented Interfaces:
ResourceModelSource
,WriteableModelSource
- Direct Known Subclasses:
FileResourceModelSource
public abstract class BaseFileResourceModelSource extends java.lang.Object implements ResourceModelSource, WriteableModelSource
A base class for a Writeable ResourceModelSource that supports the Rundeck parser formats. This class maintains cached Nodes data, and a "last modified" timestamp can be used to determine if cached or fresh data should be returned. Subclasses can define the specific ResourceFormat to use, either by returning a provider name from
getResourceFormat()
, a file extension fromgetDocumentFileExtension()
or overriddinggetResourceFormatParser()
directly.Methods implementing
WriteableModelSource
are provided, but can be overridden.This class is meant to serve as a base class for a ResourceModelSource similar to the
FileResourceModelSource
where the backend is similar to a file system.Abstract methods which should be implemented:
getResourceFormat()
getDocumentFileExtension()
writeFileData(long, InputStream)
openFileDataInputStream()
Methods which can be overridden:
- Since:
- 9/11/17
-
-
Field Summary
Fields Modifier and Type Field Description protected Framework
framework
protected NodeSetImpl
nodeSet
-
Constructor Summary
Constructors Constructor Description BaseFileResourceModelSource(Framework framework)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract java.lang.String
getDocumentFileExtension()
protected long
getLastModified()
INodeSet
getNodes()
INodeSet
getNodes(ResourceFormatParser parser)
Returns aINodeSet
object conatining the nodes config data.protected abstract java.lang.String
getResourceFormat()
protected ResourceFormatParser
getResourceFormatParser()
Uses the result ofgetResourceFormat()
orgetDocumentFileExtension()
to retrieve a ResourceFormatParser.SourceType
getSourceType()
java.lang.String
getSyntaxMimeType()
WriteableModelSource
getWriteable()
boolean
isDataWritable()
protected boolean
isSupportsLastModified()
abstract java.io.InputStream
openFileDataInputStream()
long
readData(java.io.OutputStream sink)
read current data into the sinkprotected boolean
shouldGenerateServerNode()
long
writeData(java.io.InputStream data)
Writes the data to a temp file, and attempts to parser it, then if successful it will callwriteFileData(long, InputStream)
to invoke the sub classprotected long
writeFileData(long length, java.io.InputStream tempStream)
Write the file data from the inputstream to the backing store, this implementation callswriteFileData(InputStream)
but can be overriddenabstract long
writeFileData(java.io.InputStream tempStream)
Write the file data from the inputstream to the backing store-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.dtolabs.rundeck.core.resources.WriteableModelSource
getSourceDescription, hasData
-
-
-
-
Field Detail
-
framework
protected Framework framework
-
nodeSet
protected NodeSetImpl nodeSet
-
-
Constructor Detail
-
BaseFileResourceModelSource
public BaseFileResourceModelSource(Framework framework)
-
-
Method Detail
-
getSyntaxMimeType
public java.lang.String getSyntaxMimeType()
- Specified by:
getSyntaxMimeType
in interfaceWriteableModelSource
- Returns:
- the mime type of the data
-
getResourceFormatParser
protected ResourceFormatParser getResourceFormatParser() throws ResourceModelSourceException
Uses the result ofgetResourceFormat()
orgetDocumentFileExtension()
to retrieve a ResourceFormatParser.- Returns:
- implementation of ResourceFormatParser
- Throws:
ResourceModelSourceException
-
getResourceFormat
protected abstract java.lang.String getResourceFormat()
- Returns:
- the name of the supported ResourceFormatParser provider, or null if the file extension is used
-
getDocumentFileExtension
protected abstract java.lang.String getDocumentFileExtension()
- Returns:
- the file extension of the document, or the
getResourceFormat()
must be used.
-
writeData
public long writeData(java.io.InputStream data) throws java.io.IOException, ResourceModelSourceException
Writes the data to a temp file, and attempts to parser it, then if successful it will callwriteFileData(long, InputStream)
to invoke the sub class- Specified by:
writeData
in interfaceWriteableModelSource
- Parameters:
data
- data- Returns:
- number of bytes written
- Throws:
java.io.IOException
- if an IO error occursResourceModelSourceException
- if an error occurs parsing the data.
-
writeFileData
public abstract long writeFileData(java.io.InputStream tempStream) throws java.io.IOException
Write the file data from the inputstream to the backing store- Parameters:
tempStream
- input stream- Returns:
- bytes writen
- Throws:
java.io.IOException
-
writeFileData
protected long writeFileData(long length, java.io.InputStream tempStream) throws java.io.IOException
Write the file data from the inputstream to the backing store, this implementation callswriteFileData(InputStream)
but can be overridden- Parameters:
length
- data lengthtempStream
- input stream- Returns:
- bytes writen
- Throws:
java.io.IOException
-
openFileDataInputStream
public abstract java.io.InputStream openFileDataInputStream() throws java.io.IOException, ResourceModelSourceException
- Returns:
- an input stream that reads the data from the backing store
- Throws:
java.io.IOException
ResourceModelSourceException
-
readData
public long readData(java.io.OutputStream sink) throws java.io.IOException, ResourceModelSourceException
Description copied from interface:WriteableModelSource
read current data into the sink- Specified by:
readData
in interfaceWriteableModelSource
- Returns:
- bytes written
- Throws:
java.io.IOException
ResourceModelSourceException
-
getSourceType
public SourceType getSourceType()
- Specified by:
getSourceType
in interfaceResourceModelSource
- Returns:
- the type of source, which may be writeable, by default return READ_ONLY. If it is writeable, it must
implement
WriteableModelSource
-
isDataWritable
public boolean isDataWritable()
- Returns:
- true if the model source is writable, false if the data should not be modified with
writeData(InputStream)
-
shouldGenerateServerNode
protected boolean shouldGenerateServerNode()
- Returns:
- true if the node set should always include the local server node data
-
isSupportsLastModified
protected boolean isSupportsLastModified()
- Returns:
- true if the underlying data set supports a "last modified" timestamp which should be used to determine whether the nodes data should be reloaded or cached data can be used
-
getLastModified
protected long getLastModified()
- Returns:
- last modified unix timestamp, or -1 if not available
-
getWriteable
public WriteableModelSource getWriteable()
- Specified by:
getWriteable
in interfaceResourceModelSource
- Returns:
- a WriteableModelSource if the source type is READ_WRITE
-
getNodes
public INodeSet getNodes() throws ResourceModelSourceException
- Specified by:
getNodes
in interfaceResourceModelSource
- Throws:
ResourceModelSourceException
-
getNodes
public INodeSet getNodes(ResourceFormatParser parser) throws ResourceModelSourceException
Returns aINodeSet
object conatining the nodes config data.- Parameters:
parser
- model parser- Returns:
- an instance of
INodeSet
- Throws:
ResourceModelSourceException
- on error
-
-