예제 #1
0
 def testGetSnapshotWithoutMetadata(self):
     resolver = maven.ArtifactResolver('file:./src/resources/repository/',
                                       'com.meltwater',
                                       'myservice-classifier',
                                       classifier='marathon')
     json = resolver.get('1.1.1-SNAPSHOT')
     self.assertTrue(bool(json))
예제 #2
0
 def testClassifier(self):
     resolver = maven.ArtifactResolver('file:./src/resources/repository/',
                                       'com.meltwater',
                                       'myservice-classifier',
                                       classifier='marathon')
     json = resolver.get('1.0.0')
     self.assertTrue(bool(json))
예제 #3
0
    def testGet(self):
        resolver = maven.ArtifactResolver('file:./src/resources/repository/',
                                          'com.meltwater', 'myservice')
        json = resolver.get('1.0.0')
        self.assertTrue(bool(json))

        try:
            resolver.get('0.0.0')
        except RuntimeError:
            pass
        else:
            self.fail("Expected RuntimeError")
예제 #4
0
    def testSelectVersionInclusive(self):
        resolver = maven.ArtifactResolver('file:./src/resources/repository/',
                                          'com.meltwater', 'myservice')

        def select(expression, versions):
            return resolver.selectVersion(expression, versions)

        versions = [
            '0.1.2', '1.2.0', '1.2.1', '2.0.0-SNAPSHOT', '2.0.0', '2.0.1',
            '2.0.2-SNAPSHOT'
        ]
        self.assertEquals(select('[1.0.0,2.0.0]', versions), '2.0.0')
        self.assertEquals(select('[1.0.0,2.2.0]', versions), '2.0.1')
        self.assertEquals(select('[1.0.0,1.3.0]', versions), '1.2.1')
예제 #5
0
    def testSelectVersionExclusive(self):
        resolver = maven.ArtifactResolver('file:./src/resources/repository/',
                                          'com.meltwater', 'myservice')

        def select(expression, versions):
            return resolver.selectVersion(expression, versions)

        versions = [
            '0.1.2', '1.2.0', '1.2.1', '2.0.0-SNAPSHOT', '2.0.0', '2.0.1',
            '2.0.2-SNAPSHOT'
        ]
        self.assertEquals(select('[1.0.0,2.0.0)', versions), '1.2.1')
        self.assertEquals(select('[0.1.0,2.2.0)', versions), '2.0.1')
        self.assertEquals(select('[0.0.0,1.3.0)', versions), '1.2.1')

        try:
            self.assertEquals(select('(1.2.0,1.2.0]', versions), '1.2.0')
        except RuntimeError:
            pass
        else:
            self.fail('Expected RuntimeError')
예제 #6
0
def parse_service(filename, targetdir=None, verifySecrets=False, profiles=[]):
    logging.info("Processing %s", filename)
    # Start from a service section if it exists
    with open(filename, 'r') as fd:
        try:
            document = yaml.load(fd)
        except yaml.YAMLError as e:
            raise RuntimeError("Error parsing file %s: %s" % (filename, e))

    # Merge globals.yml files into document
    path = os.path.dirname(os.path.abspath(filename))
    while '/' in path:
        candidate = os.path.join(path, 'globals.yml')
        if os.path.exists(candidate):
            document = merge_with_service(candidate, document)
        path = path[0:path.rindex('/')]

    # Merge profile .yml files into document
    document = merge_with_profiles(document, profiles)

    variables = util.FixedVariables(document.get('variables', {}))

    # Environment variables has higher precedence
    variables = util.EnvironmentVariables(variables)

    # Replace variables in entire document
    document = util.replace(document,
                            variables,
                            raiseError=False,
                            escapeVar=False)

    config = document.get('service', {})

    # Allow resolving version/uniqueVersion variables from docker registry
    variables = docker.ImageVariables.create(
        variables, document, util.rget(config, 'container', 'docker', 'image'))

    # Fetch and merge json template from maven
    if util.rget(document, 'maven', 'version') or util.rget(
            document, 'maven', 'resolve'):
        coord = document['maven']
        versionspec = coord.get('version')
        if not versionspec:
            versionspec = coord['resolve']
            logging.warn(
                "The 'resolve:' tag is deprecated, please switch to 'version:' which is a drop-in replacement in %s"
                % filename)

        resolver = maven.ArtifactResolver(coord['repository'],
                                          coord['groupid'],
                                          coord['artifactid'],
                                          coord.get('classifier'))
        version = resolver.resolve(versionspec)

        artifact = resolver.fetch(version)
        config = util.merge(config, artifact.body)
        variables = maven.ArtifactVariables(variables, artifact)

    # Merge overrides into json template
    config = util.merge(config, document.get('override', {}))

    # Substitute variables into the config
    try:
        config = util.replace(config, variables)
    except KeyError as e:
        raise RuntimeError(
            'Failed to parse %s with the following message: %s' %
            (filename, str(e.message)))

    if 'env' in config:
        config['env'] = process_env(filename, verifySecrets, config['env'])

    # Generate deploy keys and encrypt secrets
    config = secretary.apply(document, config)
    checksum = util.checksum(config)

    # Include hash of config to detect if an element has been removed
    config['labels'] = config.get('labels', {})
    config['labels']['com.meltwater.lighter.checksum'] = checksum

    # Include a docker label to sort on
    if util.rget(config, 'container', 'docker'):
        config['container']['docker']['parameters'] = config['container'][
            'docker'].get('parameters', [])
        config['container']['docker']['parameters'].append({
            'key':
            'label',
            'value':
            'com.meltwater.lighter.appid=' + config['id']
        })

    # Write json file to disk for logging purposes
    if targetdir:
        outputfile = os.path.join(targetdir, filename + '.json')

        # Exception if directory exists, e.g. because another thread created it concurrently
        try:
            os.makedirs(os.path.dirname(outputfile))
        except OSError as e:
            pass

        with open(outputfile, 'w') as fd:
            fd.write(util.toJson(config, indent=4))

    return Service(filename, document, config)
예제 #7
0
 def testResolve(self):
     resolver = maven.ArtifactResolver('file:./src/resources/repository/',
                                       'com.meltwater', 'myservice')
     self.assertEquals(resolver.resolve('[1.0.0,2.0.0)'), '1.1.0')
예제 #8
0
 def testResolveSpecificVersion(self):
     resolver = maven.ArtifactResolver('file:./src/resources/repository/',
                                       'com.meltwater', 'myservice')
     self.assertEquals(resolver.resolve('1.2.0'), '1.2.0')