Esempio n. 1
0
    def __createFromSelected(self):
        self.vc("log").debug("Creating package from selected...")
        packageType, jsonConfigFile = self.__getPackageTypeAndJsonConfigFile()
        #self.vc("log").debug("packageType = '{}'", packageType)
        #self.vc("log").debug("jsonConfigFile = '{}'", jsonConfigFile)

        # if modifying existing manifest, we already have an identifier,
        # otherwise create a new one
        manifestId = self.__getActiveManifestId()
        if manifestId is None:
            manifestHash = "%s.tfpackage" % uuid.uuid4()
        else:
            manifestHash = self.__getActiveManifestPid()

        # store the manifest file for harvesting
        packageDir = FascinatorHome.getPathFile("packages")
        packageDir.mkdirs()
        manifestFile = File(packageDir, manifestHash)
        outStream = FileOutputStream(manifestFile)
        outWriter = OutputStreamWriter(outStream, "UTF-8")
        manifest = self.__getActiveManifest()
        oldType = manifest.getType()
        if oldType is None:
            manifest.setType(packageType)
        else:
            manifest.setType(oldType)

        #self.vc("log").debug("Manifest: {}", manifest)
        outWriter.write(manifest.toString(True))
        outWriter.close()

        try:
            if manifestId is None:
                # harvest the package as an object
                username = self.vc("sessionState").get("username")
                if username is None:
                    username = "******" # necessary?
                harvester = None
                # set up config files, and make sure they are both deployed
                workflowsDir = FascinatorHome.getPathFile("harvest/workflows")
                configFile = self.__getFile(workflowsDir, jsonConfigFile)
                rulesFile = self.__getFile(workflowsDir, "packaging-rules.py")
                # run the harvest client with our packaging workflow config
                harvester = HarvestClient(configFile, manifestFile, username)
                harvester.start()
                manifestId = harvester.getUploadOid()
                harvester.shutdown()
            else:
                # update existing object
                object = StorageUtils.getDigitalObject(Services.getStorage(), manifestId)
                manifestStream = FileUtils.openInputStream(manifestFile)
                StorageUtils.createOrUpdatePayload(object, manifestHash, manifestStream)
                manifestStream.close()
                object.close()
        except Exception, ex:
            error = "Packager workflow failed: %s" % str(ex)
            log.error(error, ex)
            if harvester is not None:
                harvester.shutdown()
            return '{ "status": "failed" }'
Esempio n. 2
0
    def __createNew(self):
        print "Creating a new package..."
        packageType, jsonConfigFile = self.__getPackageTypeAndJsonConfigFile()
        print "packageType='%s'" % packageType
        print "jsonConfigFile='%s'" % jsonConfigFile

        manifestHash = "%s.tfpackage" % uuid.uuid4()
        # store the manifest file for harvesting
        packageDir = FascinatorHome.getPathFile("packages")
        packageDir.mkdirs()
        manifestFile = File(packageDir, manifestHash)
        outStream = FileOutputStream(manifestFile)
        outWriter = OutputStreamWriter(outStream, "UTF-8")

        self.vc("sessionState").set("package/active", None)
        manifest = self.__getActiveManifest()
        manifest.set("packageType", packageType)
        metaList = list(self.vc("formData").getValues("metaList"))
        for metaName in metaList:
            value = self.vc("formData").get(metaName)
            manifest.set(metaName, value)
        #
        print "------"
        print manifest
        print "------"
        manifest.store(outWriter, True)
        outWriter.close()

        try:
            # harvest the package as an object
            username = self.vc("sessionState").get("username")
            if username is None:
                username = "******" # necessary?
            harvester = None
            # set up config files, creating if necessary
            workflowsDir = FascinatorHome.getPathFile("harvest/workflows")
            configFile = self.__getFile(workflowsDir, jsonConfigFile)
            self.__getFile(workflowsDir, "packaging-rules.py")
            # run the harvest client with our packaging workflow config
            harvester = HarvestClient(configFile, manifestFile, username)
            harvester.start()
            manifestId = harvester.getUploadOid()
            harvester.shutdown()
        except Exception, ex:
            error = "Packager workflow failed: %s" % str(ex)
            log.error(error, ex)
            if harvester is not None:
                harvester.shutdown()
            return '{ status: "failed" }'
Esempio n. 3
0
 def __createFromSelected(self):
     print "Creating package from selected..."
     
     # if modifying existing manifest, we already have an identifier,
     # otherwise create a new one
     manifestId = self.__getActiveManifestId()
     if manifestId is None:
         manifestHash = "%s.tfpackage" % uuid.uuid4()
     else:
         manifestHash = self.__getActiveManifestPid()
     
     # store the manifest file for harvesting
     packageDir = FascinatorHome.getPathFile("packages")
     packageDir.mkdirs()
     manifestFile = File(packageDir, manifestHash)
     outStream = FileOutputStream(manifestFile)
     outWriter = OutputStreamWriter(outStream, "UTF-8")
     manifest = self.__getActiveManifest()
     manifest.store(outWriter, True)
     outWriter.close()
     
     try:
         if manifestId is None:
             # harvest the package as an object
             username = sessionState.get("username")
             if username is None:
                 username = "******" # necessary?
             harvester = None
             # set up config files if necessary
             workflowsDir = FascinatorHome.getPathFile("harvest/workflows")
             configFile = self.__getFile(workflowsDir, "packaging-config.json")
             rulesFile = self.__getFile(workflowsDir, "packaging-rules.py")
             # run the harvest client with our packaging workflow config
             harvester = HarvestClient(configFile, manifestFile, username)
             harvester.start()
             manifestId = harvester.getUploadOid()
             harvester.shutdown()
         else:
             # update existing object
             object = StorageUtils.storeFile(Services.getStorage(), manifestFile)
             object.close()
     except Exception, ex:
         error = "Packager workflow failed: %s" % str(ex)
         log.error(error, ex)
         if harvester is not None:
             harvester.shutdown()
         return '{ status: "failed" }'