Beispiel #1
0
func (runner *Runner) saveInfo(buildpack string, detectOutput string, releaseInfo Release) error {
	infoFile, err := os.Create(filepath.Join(runner.config.OutputDropletDir(), "staging_info.yml"))
	if err != nil {
		return err
	}

	defer infoFile.Close()

	resultFile, err := os.Create(runner.config.OutputMetadataPath())
	if err != nil {
		return err
	}

	defer resultFile.Close()

	info := models.StagingInfo{
		BuildpackKey:         buildpack,
		DetectedBuildpack:    detectOutput,
		DetectedStartCommand: releaseInfo.DefaultProcessTypes.Web,
	}

	err = candiedyaml.NewEncoder(infoFile).Encode(info)
	if err != nil {
		return err
	}

	err = json.NewEncoder(resultFile).Encode(info)
	if err != nil {
		return err
	}

	return nil
}
func startAgent() *gexec.Session {
	config := &agentconfig.Config{
		DefaultConfPath:     helpers.AssetPath("redis.conf.default"),
		ConfPath:            redisConfPath,
		MonitExecutablePath: helpers.AssetPath("fake_monit"),
		Port:                "9876",
		AuthConfiguration: agentconfig.AuthConfiguration{
			Username: "******",
			Password: "******",
		},
	}

	configFile, err := ioutil.TempFile("", "config.yml")
	Expect(err).ToNot(HaveOccurred())

	encoder := candiedyaml.NewEncoder(configFile)
	err = encoder.Encode(config)
	Ω(err).ShouldNot(HaveOccurred())
	configFile.Close()

	agentPath, err := gexec.Build("github.com/pivotal-cf/cf-redis-broker/cmd/agent")
	Ω(err).ShouldNot(HaveOccurred())

	session, err := gexec.Start(
		exec.Command(agentPath, fmt.Sprintf("-agentConfig=%s", configFile.Name())),
		GinkgoWriter,
		GinkgoWriter,
	)
	Ω(err).ShouldNot(HaveOccurred())

	Expect(helpers.ServiceAvailable(9876)).To(BeTrue())
	return session
}
Beispiel #3
0
func resources(name string) {
	cf := cloudformation.NewFromEnv()
	ec2Client := ec2.NewFromEnv()
	elbClient := elb.NewFromEnv()

	resources, err := cf.DescribeStackResources(
		cloudformation.DescribeStackResourcesParameters{
			StackName: name,
		},
	)
	if err != nil {
		fatal(err)
	}

	stub := make(map[string]map[string]interface{})

	for _, resource := range resources.DescribeStackResourcesResult.StackResources {
		typeSegments := strings.Split(resource.ResourceType, "::")
		typeBase := typeSegments[len(typeSegments)-1]

		byType, found := stub[typeBase]
		if !found {
			byType = make(map[string]interface{})
			stub[typeBase] = byType
		}

		cleanName := strings.Replace(resource.LogicalResourceId, typeBase, "", 1)
		if cleanName == "" {
			cleanName = resource.LogicalResourceId
		}

		byType[cleanName] = resource.PhysicalResourceId
	}

	err = grabSecurityGroupNames(stub, ec2Client)
	if err != nil {
		fatal(err)
	}

	err = grabSubnetInfo(stub, ec2Client)
	if err != nil {
		fatal(err)
	}

	err = grabLoadBalancerDNSNames(stub, elbClient)
	if err != nil {
		fatal(err)
	}

	err = candiedyaml.NewEncoder(os.Stdout).Encode(map[string]interface{}{
		"Region":          ec2Client.Client.Region,
		"AccessKeyID":     ec2Client.Client.Key,
		"SecretAccessKey": ec2Client.Client.Secret,
		"Resources":       stub,
	})
	if err != nil {
		fatal(err)
	}
}
Beispiel #4
0
func writeConfig() {
	fileToWrite, err := os.Create(configPath)
	Ω(err).ShouldNot(HaveOccurred())

	encoder := candiedyaml.NewEncoder(fileToWrite)
	err = encoder.Encode(rootConfig)
	Ω(err).ShouldNot(HaveOccurred())
}
Beispiel #5
0
func (maker ComponentMaker) Router() ifrit.Runner {
	_, routerPort, err := net.SplitHostPort(maker.Addresses.Router)
	Expect(err).NotTo(HaveOccurred())

	routerPortInt, err := strconv.Atoi(routerPort)
	Expect(err).NotTo(HaveOccurred())

	natsHost, natsPort, err := net.SplitHostPort(maker.Addresses.NATS)
	Expect(err).NotTo(HaveOccurred())

	natsPortInt, err := strconv.Atoi(natsPort)
	Expect(err).NotTo(HaveOccurred())

	routerConfig := &gorouterconfig.Config{
		Port: uint16(routerPortInt),

		PruneStaleDropletsIntervalInSeconds: 5,
		DropletStaleThresholdInSeconds:      10,
		PublishActiveAppsIntervalInSeconds:  0,
		StartResponseDelayIntervalInSeconds: 1,

		Nats: []gorouterconfig.NatsConfig{
			{
				Host: natsHost,
				Port: uint16(natsPortInt),
			},
		},
		Logging: gorouterconfig.LoggingConfig{
			File:          "/dev/stdout",
			Level:         "info",
			MetronAddress: "127.0.0.1:65534", // nonsense to make dropsonde happy
		},
	}

	configFile, err := ioutil.TempFile(os.TempDir(), "router-config")
	Expect(err).NotTo(HaveOccurred())

	defer configFile.Close()

	err = candiedyaml.NewEncoder(configFile).Encode(routerConfig)
	Expect(err).NotTo(HaveOccurred())

	return ginkgomon.New(ginkgomon.Config{
		Name:              "router",
		AnsiColorCode:     "32m",
		StartCheck:        "router.started",
		StartCheckTimeout: 10 * time.Second, // it waits 1 second before listening. yep.
		Command: exec.Command(
			maker.Artifacts.Executables["router"],
			"-c", configFile.Name(),
		),
		Cleanup: func() {
			err := os.Remove(configFile.Name())
			Expect(err).NotTo(HaveOccurred())
		},
	})
}
Beispiel #6
0
func (p Property) DefaultAsYAML() (string, error) {
	var b bytes.Buffer

	err := candiedyaml.NewEncoder(&b).Encode(p.Default)
	if err != nil {
		return "", bosherr.WrapError(err, "Generating yaml for property '%s' default", p.Name)
	}

	return b.String(), nil
}
Beispiel #7
0
func (e PropertyExample) ValueAsYAML() (string, error) {
	var b bytes.Buffer

	err := candiedyaml.NewEncoder(&b).Encode(e.Value)
	if err != nil {
		return "", bosherr.WrapError(err, "Generating yaml for property example")
	}

	return b.String(), nil
}
Beispiel #8
0
func ConvertIgnoreOmitEmpty(from, to interface{}) error {
	var buffer bytes.Buffer

	encoder := yaml.NewEncoder(&buffer)
	encoder.IgnoreOmitEmpty = true

	if err := encoder.Encode(from); err != nil {
		return err
	}

	decoder := yaml.NewDecoder(&buffer)

	if err := decoder.Decode(to); err != nil {
		return err
	}

	return nil
}
Beispiel #9
0
func (runner *Runner) saveInfo(infoFilePath, buildpack, detectOutput string, releaseInfo Release) error {
	deaInfoFile, err := os.Create(infoFilePath)
	if err != nil {
		return err
	}
	defer deaInfoFile.Close()

	err = candiedyaml.NewEncoder(deaInfoFile).Encode(DeaStagingInfo{
		DetectedBuildpack: detectOutput,
		StartCommand:      releaseInfo.DefaultProcessTypes.Web,
	})
	if err != nil {
		return err
	}

	resultFile, err := os.Create(runner.config.OutputMetadata())
	if err != nil {
		return err
	}
	defer resultFile.Close()

	executionMetadata, err := json.Marshal(protocol.ExecutionMetadata{
		StartCommand: releaseInfo.DefaultProcessTypes.Web,
	})
	if err != nil {
		return err
	}

	err = json.NewEncoder(resultFile).Encode(buildpack_app_lifecycle.StagingResult{
		BuildpackKey:         buildpack,
		DetectedBuildpack:    detectOutput,
		ExecutionMetadata:    string(executionMetadata),
		DetectedStartCommand: map[string]string{"web": releaseInfo.DefaultProcessTypes.Web},
	})
	if err != nil {
		return err
	}

	return nil
}