예제 #1
0
 /// <summary>
 /// Loads ToscaServiceTemplate from file
 /// </summary>
 /// <param name="filePath"></param>
 /// <returns></returns>
 /// <exception cref="ToscaParsingException">Thrown when file is not valid according to YAML or TOSCA</exception>
 public ToscaServiceTemplate Load(string filePath)
 {
     using (var stream = fileSystem.File.Open(filePath, FileMode.Open))
     {
         return(toscaParser.Parse(stream));
     }
 }
예제 #2
0
        public void ToscaMetadata_Deserialized_Successfully()
        {
            var toscaMeta = @"
TOSCA-Meta-File-Version: 1.0
CSAR-Version: 1.1
Created-By: OASIS TOSCA TC
Entry-Definitions: definitions/tosca_elk.yaml";

            using (var memoryStream = toscaMeta.ToMemoryStream())
            {
                var toscaMetadata = metadataParser.Parse(memoryStream);

                toscaMetadata.ToscaMetaFileVersion.Should().Be(new Version("1.0"));
                toscaMetadata.CsarVersion.Should().Be(new Version("1.1"));
                toscaMetadata.CreatedBy.Should().Be("OASIS TOSCA TC");
                toscaMetadata.EntryDefinitions.Should().Be("definitions/tosca_elk.yaml");
            }
        }
예제 #3
0
 /// <summary>
 /// Loads Cloud Service Archive (CSAR) file and all its dependencies
 /// </summary>
 /// <param name="archiveStream">Stream to Cloud Service Archive (CSAR) zip file</param>
 /// <param name="alternativePath">Path for dependencies lookup outside the archive</param>
 /// <exception cref="ToscaMetadataFileNotFoundException">Thrown when TOSCA.meta file not found in the archive.</exception>
 /// <exception cref="InvalidDataException">The contents of the stream could not be interpreted as a zip archive or the archive is corrupt and cannot be read.</exception>
 /// <returns>A valid instance of ToscaCloudServiceArchive</returns>
 public ToscaCloudServiceArchive Load(Stream archiveStream, string alternativePath = null)
 {
     using (var archive = CreateZipArchiveFromStream(archiveStream))
     {
         var archiveEntries           = archive.GetArchiveEntriesDictionary();
         var toscaMetaArchiveEntry    = GetToscaMetaArchiveEntry(archiveEntries);
         var toscaMetadata            = metadataParser.Parse(toscaMetaArchiveEntry.Open());
         var toscaCloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);
         LoadDependenciesRecursively(toscaCloudServiceArchive, archiveEntries, toscaMetadata.EntryDefinitions, alternativePath);
         ValidateCloudServiceArchive(toscaCloudServiceArchive);
         return(toscaCloudServiceArchive);
     }
 }
예제 #4
0
        private ToscaServiceTemplate LoadToscaServiceTemplate(string alternativePath, IReadOnlyDictionary <string, ZipArchiveEntry> archiveEntries, string filePath, ToscaCloudServiceArchive toscaCloudServiceArchive)
        {
            var importStream = GetImportStream(alternativePath, archiveEntries, filePath);

            try
            {
                return(serviceTemplateParser.Parse(importStream));
            }
            catch (ToscaBaseException toscaBaseException)
            {
                throw new ToscaParsingException(
                          string.Format("Failed to load definitions file {0} due to an error: {1}", filePath, toscaBaseException.GetaAllMessages()),
                          toscaBaseException);
            }
        }