@@ -1846,6 +1846,68 @@ func (fs *FileSystem) readProjectOutput(t *bolt.Tx, workspaceId, projectId, proj
1846
1846
return projOutput , f , nil
1847
1847
}
1848
1848
1849
+ // ReadProjectOutputGraph returns the graph file from the target artifacts for an application
1850
+ func (fs * FileSystem ) ReadProjectOutputGraph (workspaceId , projectId , projOutputId string ) (projOutput types.ProjectOutput , file io.Reader , err error ) {
1851
+ db , err := fs .GetDatabase (true )
1852
+ if err != nil {
1853
+ return projOutput , file , err
1854
+ }
1855
+ defer db .Close ()
1856
+ err = db .View (func (t * bolt.Tx ) error {
1857
+ projOutput , file , err = fs .readProjectOutputGraph (t , workspaceId , projectId , projOutputId )
1858
+ return err
1859
+ })
1860
+ return projOutput , file , err
1861
+ }
1862
+
1863
+ func (fs * FileSystem ) readProjectOutputGraph (t * bolt.Tx , workspaceId , projectId , projOutputId string ) (projOutput types.ProjectOutput , file io.Reader , err error ) {
1864
+ project , err := fs .readProject (t , workspaceId , projectId )
1865
+ if err != nil {
1866
+ return types.ProjectOutput {}, nil , err
1867
+ }
1868
+ projOutput , ok := project .Outputs [projOutputId ]
1869
+ if ! ok {
1870
+ return projOutput , nil , types.ErrorDoesNotExist {Id : projOutputId }
1871
+ }
1872
+ if projOutput .Status == types .ProjectOutputStatusInProgress {
1873
+ return projOutput , nil , types.ErrorOngoing {Id : projOutputId }
1874
+ }
1875
+ if projOutput .Status != types .ProjectOutputStatusDoneSuccess {
1876
+ if projOutput .Status == types .ProjectOutputStatusDoneError {
1877
+ return projOutput , nil , types.ErrorValidation {Reason : fmt .Sprintf ("an error occurred during transformation of the output %s of project %s" , projOutputId , projectId )}
1878
+ }
1879
+ return projOutput , nil , types.ErrorDoesNotExist {Id : projOutputId }
1880
+ }
1881
+ curDir := filepath .Join (common .Config .DataDir , PROJECTS_DIR , projectId , PROJECT_OUTPUTS_DIR , projOutputId , "output" )
1882
+ if err := fs .processGraph (curDir ); err != nil {
1883
+ return projOutput , nil , fmt .Errorf ("failed to process the project output graph file inside the output directory %s . Error: %q" , curDir , err )
1884
+ }
1885
+ projOutputPath := filepath .Join (curDir , "m2k-proc-graph.json" )
1886
+ f , err := os .Open (projOutputPath )
1887
+ if err != nil {
1888
+ return projOutput , nil , fmt .Errorf ("failed to read the project output file at path %s . Error: %q" , projOutputPath , err )
1889
+ }
1890
+ return projOutput , f , nil
1891
+ }
1892
+
1893
+ func (fs * FileSystem ) processGraph (currentRunDir string ) error {
1894
+ logrus .Infof ("Starting graph at directory %s" , currentRunDir )
1895
+ cmdArgs := []string {"graph" , "--output" , "m2k-proc-graph.json" }
1896
+ logrus .Infof ("graph cmdArgs: %+v" , cmdArgs )
1897
+ ctx := context .Background ()
1898
+ if common .Config .PlanTimeoutSeconds > 0 {
1899
+ var cancel context.CancelFunc
1900
+ ctx , cancel = context .WithTimeout (ctx , time .Duration (common .Config .PlanTimeoutSeconds )* time .Second )
1901
+ defer cancel ()
1902
+ }
1903
+ cmd := exec .CommandContext (ctx , common .APP_NAME , cmdArgs ... )
1904
+ cmd .Dir = currentRunDir
1905
+ if err := cmd .Run (); err != nil {
1906
+ return fmt .Errorf ("failed to start the graph command. Error: %q" , err )
1907
+ }
1908
+ return nil
1909
+ }
1910
+
1849
1911
// DeleteProjectOutput deletes the project output
1850
1912
func (fs * FileSystem ) DeleteProjectOutput (workspaceId , projectId , projOutputId string ) error {
1851
1913
db , err := fs .GetDatabase (false )
0 commit comments