Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
Refactor Build to use BuildInitialState
Browse files Browse the repository at this point in the history
[#118443493]

Signed-off-by: Kam Leung <[email protected]>
  • Loading branch information
dpb587-pivotal authored and Kam Leung committed May 2, 2016
1 parent 92a3ed5 commit d8e5ff0
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions deployment/instance/state/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ type renderedJobs struct {
}

func (b *builder) Build(jobName string, instanceID int, deploymentManifest bideplmanifest.Manifest, stage biui.Stage, agentState agentclient.AgentState) (State, error) {

initialState, err := b.BuildInitialState(jobName, instanceID, deploymentManifest)
if err != nil {
return nil, bosherr.WrapErrorf(err, "Building initial state '%s", jobName)
}

deploymentJob, found := deploymentManifest.FindJobByName(jobName)
if !found {
return nil, bosherr.Errorf("Job '%s' not found in deployment manifest", jobName)
Expand All @@ -70,21 +76,7 @@ func (b *builder) Build(jobName string, instanceID int, deploymentManifest bidep
releaseJobProperties[releaseJob.Name] = releaseJob.Properties
}

networkInterfaces, err := deploymentManifest.NetworkInterfaces(deploymentJob.Name)
if err != nil {
return nil, bosherr.WrapErrorf(err, "Finding networks for job '%s", jobName)
}

// convert map to array
networkRefs := make([]NetworkRef, 0, len(networkInterfaces))
for networkName, networkInterface := range networkInterfaces {
networkRefs = append(networkRefs, NetworkRef{
Name: networkName,
Interface: networkInterface,
})
}

defaultAddress, err := b.defaultAddress(networkRefs, agentState)
defaultAddress, err := b.defaultAddress(initialState.NetworkInterfaces(), agentState)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -129,7 +121,7 @@ func (b *builder) Build(jobName string, instanceID int, deploymentManifest bidep
deploymentName: deploymentManifest.Name,
name: jobName,
id: instanceID,
networks: networkRefs,
networks: initialState.NetworkInterfaces(),
compiledPackages: compiledDeploymentPackageRefs,
renderedJobs: renderedJobRefs,
renderedJobListArchive: renderedJobListArchiveBlobRef,
Expand Down

0 comments on commit d8e5ff0

Please sign in to comment.