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
WriteableModelSourceare provided, but can be overridden.This class is meant to serve as a base class for a ResourceModelSource similar to the
FileResourceModelSourcewhere 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 Frameworkframeworkprotected NodeSetImplnodeSet
-
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.StringgetDocumentFileExtension()protected longgetLastModified()INodeSetgetNodes()INodeSetgetNodes(ResourceFormatParser parser)Returns aINodeSetobject conatining the nodes config data.protected abstract java.lang.StringgetResourceFormat()protected ResourceFormatParsergetResourceFormatParser()Uses the result ofgetResourceFormat()orgetDocumentFileExtension()to retrieve a ResourceFormatParser.SourceTypegetSourceType()java.lang.StringgetSyntaxMimeType()WriteableModelSourcegetWriteable()booleanisDataWritable()protected booleanisSupportsLastModified()abstract java.io.InputStreamopenFileDataInputStream()longreadData(java.io.OutputStream sink)read current data into the sinkprotected booleanshouldGenerateServerNode()longwriteData(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 longwriteFileData(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 longwriteFileData(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:
getSyntaxMimeTypein 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, ResourceModelSourceExceptionWrites 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:
writeDatain 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.IOExceptionWrite 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.IOExceptionWrite 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.IOExceptionResourceModelSourceException
-
readData
public long readData(java.io.OutputStream sink) throws java.io.IOException, ResourceModelSourceExceptionDescription copied from interface:WriteableModelSourceread current data into the sink- Specified by:
readDatain interfaceWriteableModelSource- Returns:
- bytes written
- Throws:
java.io.IOExceptionResourceModelSourceException
-
getSourceType
public SourceType getSourceType()
- Specified by:
getSourceTypein 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:
getWriteablein interfaceResourceModelSource- Returns:
- a WriteableModelSource if the source type is READ_WRITE
-
getNodes
public INodeSet getNodes() throws ResourceModelSourceException
- Specified by:
getNodesin interfaceResourceModelSource- Throws:
ResourceModelSourceException
-
getNodes
public INodeSet getNodes(ResourceFormatParser parser) throws ResourceModelSourceException
Returns aINodeSetobject conatining the nodes config data.- Parameters:
parser- model parser- Returns:
- an instance of
INodeSet - Throws:
ResourceModelSourceException- on error
-
-