Retire FileUploader and subtypes (#1154)

This commit is contained in:
Andrzej Cichocki 2017-08-04 15:57:11 +01:00 committed by GitHub
parent 3fbc5fe555
commit 42e29d3b22
8 changed files with 16 additions and 77 deletions

View File

@ -213,10 +213,6 @@ interface CordaRPCOps : RPCOps {
*/
fun uploadAttachment(jar: InputStream): SecureHash
// TODO: Remove this from the interface
@Deprecated("This service will be removed in a future milestone")
fun uploadFile(dataType: String, name: String?, file: InputStream): String
/**
* Authorise a contract state upgrade.
* This will store the upgrade authorisation in the vault, and will be queried by [ContractUpgradeFlow.Acceptor] during contract upgrade process.

View File

@ -211,8 +211,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
// TODO Remove this once the cash stuff is in its own CorDapp
registerInitiatedFlow(IssuerFlow.Issuer::class.java)
initUploaders()
runOnStop += network::stop
_networkMapRegistrationFuture.setFuture(registerWithNetworkMapIfConfigured())
smm.start()
@ -478,11 +476,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
.filterNot { isAbstract(it.modifiers) }
}
private fun initUploaders() {
_services.uploaders += attachments
cordappServices.values.filterIsInstanceTo(_services.uploaders, AcceptsFileUpload::class.java)
}
private fun makeVaultObservers() {
VaultSoftLockManager(services.vaultService, smm)
ScheduledActivityObserver(services)
@ -765,7 +758,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
private inner class ServiceHubInternalImpl : ServiceHubInternal, SingletonSerializeAsToken() {
override val rpcFlows = ArrayList<Class<out FlowLogic<*>>>()
override val uploaders = ArrayList<FileUploader>()
override val stateMachineRecordedTransactionMapping = DBTransactionMappingStorage()
override val auditService = DummyAuditService()
override val monitoringService = MonitoringService(MetricRegistry())

View File

@ -148,14 +148,6 @@ class CordaRPCOpsImpl(
override fun authoriseContractUpgrade(state: StateAndRef<*>, upgradedContractClass: Class<out UpgradedContract<*, *>>) = services.vaultService.authoriseContractUpgrade(state, upgradedContractClass)
override fun deauthoriseContractUpgrade(state: StateAndRef<*>) = services.vaultService.deauthoriseContractUpgrade(state)
override fun currentNodeTime(): Instant = Instant.now(services.clock)
@Suppress("OverridingDeprecatedMember", "DEPRECATION")
override fun uploadFile(dataType: String, name: String?, file: InputStream): String {
val acceptor = services.uploaders.firstOrNull { it.accepts(dataType) }
return database.transaction {
acceptor?.upload(file) ?: throw RuntimeException("Cannot find file upload acceptor for $dataType")
}
}
override fun waitUntilRegisteredWithNetworkMap() = services.networkMapCache.mapServiceRegistered
override fun partyFromKey(key: PublicKey) = services.identityService.partyFromKey(key)
@Suppress("DEPRECATION")

View File

@ -1,15 +0,0 @@
package net.corda.node.services.api
/**
* A service that implements AcceptsFileUpload can have new binary data provided to it via an HTTP upload.
*/
// TODO This is no longer used and can be removed
interface AcceptsFileUpload : FileUploader {
/** A string that prefixes the URLs, e.g. "attachments" or "interest-rates". Should be OK for URLs. */
val dataTypePrefix: String
/** What file extensions are acceptable for the file to be handed to upload() */
val acceptableFileExtensions: List<String>
override fun accepts(type: String) = type == dataTypePrefix
}

View File

@ -23,7 +23,6 @@ import net.corda.node.services.messaging.MessagingService
import net.corda.node.services.statemachine.FlowLogicRefFactoryImpl
import net.corda.node.services.statemachine.FlowStateMachineImpl
import net.corda.node.utilities.CordaPersistence
import java.io.InputStream
/**
* Session ID to use for services listening for the first message in a session (before a
@ -68,24 +67,6 @@ sealed class NetworkCacheError : Exception() {
class DeregistrationFailed : NetworkCacheError()
}
/**
* An interface that denotes a service that can accept file uploads.
*/
// TODO This is no longer used and can be removed
interface FileUploader {
/**
* Accepts the data in the given input stream, and returns some sort of useful return message that will be sent
* back to the user in the response.
*/
fun upload(file: InputStream): String
/**
* Check if this service accepts this type of upload. For example if you are uploading interest rates this could
* be "my-service-interest-rates". Type here does not refer to file extentions or MIME types.
*/
fun accepts(type: String): Boolean
}
interface ServiceHubInternal : PluginServiceHub {
companion object {
private val log = loggerFor<ServiceHubInternal>()
@ -108,10 +89,6 @@ interface ServiceHubInternal : PluginServiceHub {
val database: CordaPersistence
val configuration: NodeConfiguration
@Suppress("DEPRECATION")
@Deprecated("This service will be removed in a future milestone")
val uploaders: List<FileUploader>
override fun recordTransactions(txs: Iterable<SignedTransaction>) {
val recordedTransactions = txs.filter { validatedTransactions.addTransaction(it) }
require(recordedTransactions.isNotEmpty()) { "No transactions passed in for recording" }

View File

@ -12,7 +12,6 @@ import net.corda.core.crypto.SecureHash
import net.corda.core.node.services.AttachmentStorage
import net.corda.core.serialization.*
import net.corda.core.utilities.loggerFor
import net.corda.node.services.api.AcceptsFileUpload
import net.corda.node.services.database.RequeryConfiguration
import net.corda.node.services.persistence.schemas.requery.AttachmentEntity
import net.corda.node.services.persistence.schemas.requery.Models
@ -31,7 +30,7 @@ import javax.annotation.concurrent.ThreadSafe
*/
@ThreadSafe
class NodeAttachmentService(dataSourceProperties: Properties, metrics: MetricRegistry, databaseProperties: Properties?)
: AttachmentStorage, AcceptsFileUpload, SingletonSerializeAsToken() {
: AttachmentStorage, SingletonSerializeAsToken() {
companion object {
private val log = loggerFor<NodeAttachmentService>()
}
@ -196,9 +195,4 @@ class NodeAttachmentService(dataSourceProperties: Properties, metrics: MetricReg
}
require(count > 0) { "Stream is either empty or not a JAR/ZIP" }
}
// Implementations for AcceptsFileUpload
override val dataTypePrefix = "attachment"
override val acceptableFileExtensions = listOf(".jar", ".zip")
override fun upload(file: InputStream) = importAttachment(file).toString()
}

View File

@ -34,7 +34,6 @@ open class MockServiceHubInternal(
val identity: IdentityService? = MOCK_IDENTITY_SERVICE,
override val attachments: AttachmentStorage = MockAttachmentStorage(),
override val validatedTransactions: WritableTransactionStorage = MockTransactionStorage(),
override val uploaders: List<FileUploader> = listOf<FileUploader>(),
override val stateMachineRecordedTransactionMapping: StateMachineRecordedTransactionMappingStorage = MockStateMachineRecordedTransactionMappingStorage(),
val mapCache: NetworkMapCacheInternal? = null,
val scheduler: SchedulerService? = null,

View File

@ -17,7 +17,6 @@ class DataUploadServlet : HttpServlet() {
@Throws(IOException::class)
override fun doPost(req: HttpServletRequest, resp: HttpServletResponse) {
@Suppress("DEPRECATION") // Bogus warning due to superclass static method being deprecated.
val isMultipart = ServletFileUpload.isMultipartContent(req)
val rpc = servletContext.getAttribute("rpc") as CordaRPCOps
@ -34,20 +33,25 @@ class DataUploadServlet : HttpServlet() {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Got an upload request with no files")
return
}
fun reportError(message: String) {
println(message) // Show in webserver window.
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, message)
}
while (iterator.hasNext()) {
val item = iterator.next()
log.info("Receiving ${item.name}")
try {
val dataType = req.pathInfo.substring(1).substringBefore('/')
@Suppress("DEPRECATION") // TODO: Replace the use of uploadFile
messages += rpc.uploadFile(dataType, item.name, item.openStream())
log.info("${item.name} successfully accepted: ${messages.last()}")
} catch(e: RuntimeException) {
println(e)
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Got a file upload request for an unknown data type")
if (dataType != "attachment") {
reportError("Got a file upload request for an unknown data type $dataType")
continue
}
try {
messages += rpc.uploadAttachment(item.openStream()).toString()
} catch (e: RuntimeException) {
reportError(e.toString())
continue
}
log.info("${item.name} successfully accepted: ${messages.last()}")
}
// Send back the hashes as a convenience for the user.