Skip to content

Commit c854127

Browse files
authored
Add pipeline info to metadata.json (#3677)
## Changes Output `id` and `relative_path` for each pipeline to `metadata.json` during deploy ## Why To enable DABs integrations in the Lakeflow UI ## Tests Updated existing test <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 4475762 commit c854127

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

bundle/deploy/metadata/compute.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (m *compute) Apply(_ context.Context, b *bundle.Bundle) diag.Diagnostics {
3535
}
3636

3737
// Set job config paths in metadata
38-
jobsMetadata := make(map[string]*metadata.Job)
38+
jobsMetadata := make(map[string]*metadata.Resource)
3939
for name, job := range b.Config.Resources.Jobs {
4040
// Compute config file path the job is defined in, relative to the bundle
4141
// root
@@ -45,13 +45,31 @@ func (m *compute) Apply(_ context.Context, b *bundle.Bundle) diag.Diagnostics {
4545
return diag.Errorf("failed to compute relative path for job %s: %v", name, err)
4646
}
4747
// Metadata for the job
48-
jobsMetadata[name] = &metadata.Job{
48+
jobsMetadata[name] = &metadata.Resource{
4949
ID: job.ID,
5050
RelativePath: filepath.ToSlash(relativePath),
5151
}
5252
}
5353
b.Metadata.Config.Resources.Jobs = jobsMetadata
5454

55+
// Set pipeline config paths in metadata
56+
pipelinesMetadata := make(map[string]*metadata.Resource)
57+
for name, pipeline := range b.Config.Resources.Pipelines {
58+
// Compute config file path the pipeline is defined in, relative to the bundle
59+
// root
60+
l := b.Config.GetLocation("resources.pipelines." + name)
61+
relativePath, err := filepath.Rel(b.BundleRootPath, l.File)
62+
if err != nil {
63+
return diag.Errorf("failed to compute relative path for pipeline %s: %v", name, err)
64+
}
65+
// Metadata for the pipeline
66+
pipelinesMetadata[name] = &metadata.Resource{
67+
ID: pipeline.ID,
68+
RelativePath: filepath.ToSlash(relativePath),
69+
}
70+
}
71+
b.Metadata.Config.Resources.Pipelines = pipelinesMetadata
72+
5573
// Set file upload destination of the bundle in metadata
5674
b.Metadata.Config.Workspace.FilePath = b.Config.Workspace.FilePath
5775
// In source-linked deployment files are not copied and resources use source files, therefore we use sync path as file path in metadata

bundle/deploy/metadata/compute_test.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/databricks/cli/bundle/metadata"
1212
"github.com/databricks/cli/libs/dyn"
1313
"github.com/databricks/databricks-sdk-go/service/jobs"
14+
"github.com/databricks/databricks-sdk-go/service/pipelines"
1415
"github.com/stretchr/testify/assert"
1516
"github.com/stretchr/testify/require"
1617
)
@@ -49,15 +50,27 @@ func TestComputeMetadataMutator(t *testing.T) {
4950
},
5051
},
5152
Pipelines: map[string]*resources.Pipeline{
52-
"my-pipeline": {},
53+
"my-pipeline-1": {
54+
BaseResource: resources.BaseResource{ID: "3333"},
55+
CreatePipeline: pipelines.CreatePipeline{
56+
Name: "My Pipeline One",
57+
},
58+
},
59+
"my-pipeline-2": {
60+
BaseResource: resources.BaseResource{ID: "4444"},
61+
CreatePipeline: pipelines.CreatePipeline{
62+
Name: "My Pipeline Two",
63+
},
64+
},
5365
},
5466
},
5567
},
5668
}
5769

5870
bundletest.SetLocation(b, "resources.jobs.my-job-1", []dyn.Location{{File: "a/b/c"}})
5971
bundletest.SetLocation(b, "resources.jobs.my-job-2", []dyn.Location{{File: "d/e/f"}})
60-
bundletest.SetLocation(b, "resources.pipelines.my-pipeline", []dyn.Location{{File: "abc"}})
72+
bundletest.SetLocation(b, "resources.pipelines.my-pipeline-1", []dyn.Location{{File: "x/y/z"}})
73+
bundletest.SetLocation(b, "resources.pipelines.my-pipeline-2", []dyn.Location{{File: "u/v/w"}})
6174

6275
expectedMetadata := metadata.Metadata{
6376
Version: metadata.Version,
@@ -74,7 +87,7 @@ func TestComputeMetadataMutator(t *testing.T) {
7487
},
7588
},
7689
Resources: metadata.Resources{
77-
Jobs: map[string]*metadata.Job{
90+
Jobs: map[string]*metadata.Resource{
7891
"my-job-1": {
7992
RelativePath: "a/b/c",
8093
ID: "1111",
@@ -84,6 +97,16 @@ func TestComputeMetadataMutator(t *testing.T) {
8497
ID: "2222",
8598
},
8699
},
100+
Pipelines: map[string]*metadata.Resource{
101+
"my-pipeline-1": {
102+
RelativePath: "x/y/z",
103+
ID: "3333",
104+
},
105+
"my-pipeline-2": {
106+
RelativePath: "u/v/w",
107+
ID: "4444",
108+
},
109+
},
87110
},
88111
},
89112
}

bundle/metadata/metadata.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Workspace struct {
1414
FilePath string `json:"file_path"`
1515
}
1616

17-
type Job struct {
17+
type Resource struct {
1818
ID string `json:"id,omitempty"`
1919

2020
// Relative path from the bundle root to the configuration file that holds
@@ -23,7 +23,8 @@ type Job struct {
2323
}
2424

2525
type Resources struct {
26-
Jobs map[string]*Job `json:"jobs,omitempty"`
26+
Jobs map[string]*Resource `json:"jobs,omitempty"`
27+
Pipelines map[string]*Resource `json:"pipelines,omitempty"`
2728
}
2829

2930
type Config struct {

0 commit comments

Comments
 (0)