Skip to content

Commit

Permalink
Revert "update get deployment query (#1365)" (#1371)
Browse files Browse the repository at this point in the history
This reverts commit 4fa1191.
  • Loading branch information
Simpcyclassy authored Aug 29, 2023
1 parent c05a3b2 commit 35f7530
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 113 deletions.
90 changes: 21 additions & 69 deletions houston/deployment.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package houston

import (
"encoding/json"
"fmt"
"time"
)

var errDeploymentNotFound = fmt.Errorf("deployment not found")
import "time"

// ListDeploymentsRequest - filters to list deployments according to set values
type ListDeploymentsRequest struct {
Expand Down Expand Up @@ -336,27 +330,25 @@ var (
},
{
version: "0.29.0",
query: generateGetDeploymentQuery("id"),
},
{
version: "0.30.8",
query: generateGetDeploymentQuery("deploymentId"),
},
{
version: "0.32.0",
query: generateGetDeploymentQuery("id"),
},
{
version: "0.32.3",
query: generateGetDeploymentQuery("deploymentId"),
},
{
version: "0.33.0",
query: generateGetDeploymentQuery("id"),
},
{
version: "0.33.1",
query: generateGetDeploymentQuery("deploymentId"),
query: `
query GetDeployment(
$id: String!
){
deployment(
where: {id: $id}
){
id
airflowVersion
desiredAirflowVersion
runtimeVersion
desiredRuntimeVersion
runtimeAirflowVersion
urls {
type
url
}
}
}`,
},
}

Expand Down Expand Up @@ -472,29 +464,6 @@ var (
}`
)

// GenerateQuery generates the deployment query based on the given version and query parameter
func generateGetDeploymentQuery(queryParam string) string {
return `
query GetDeployment(
$id: String!
) {
deployment(
where: {` + queryParam + `: $id}
) {
id
airflowVersion
desiredAirflowVersion
runtimeVersion
desiredRuntimeVersion
runtimeAirflowVersion
urls {
type
url
}
}
}`
}

// CreateDeployment - create a deployment
func (h ClientImplementation) CreateDeployment(vars map[string]interface{}) (*Deployment, error) {
reqQuery := DeploymentCreateRequest.GreatestLowerBound(version)
Expand Down Expand Up @@ -582,24 +551,7 @@ func (h ClientImplementation) GetDeployment(deploymentID string) (*Deployment, e
return nil, handleAPIErr(err)
}

var deploymentSlice []Deployment
var deployment Deployment

err = json.Unmarshal(res.Data.GetDeployment, &deployment)
if err == nil {
return &deployment, nil
}

err = json.Unmarshal(res.Data.GetDeployment, &deploymentSlice)
if err != nil {
return nil, handleAPIErr(err)
}

if len(deploymentSlice) > 0 {
return &deploymentSlice[0], nil
}

return nil, handleAPIErr(fmt.Errorf("GetDeployment failed for id: %s: %w", deploymentID, errDeploymentNotFound))
return &res.Data.GetDeployment, nil
}

// UpdateDeploymentAirflow - update airflow on a deployment
Expand Down
62 changes: 20 additions & 42 deletions houston/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,25 @@ func TestGetDeployment(t *testing.T) {

mockDeployment := &Response{
Data: ResponseData{
GetDeployment: []byte(`
{
"id": "deployment-test-id",
"type": "airflow",
"label": "test deployment",
"releaseName": "prehistoric-gravity-930",
"version": "2.2.0",
"airflowVersion": "2.2.0",
"desiredAirflowVersion": "2.2.0",
"deploymentInfo": {},
"workspace": {
"id": "test-workspace-id"
},
"urls": [
{"type": "airflow", "url": "http://airflow.com"},
{"type": "flower", "url": "http://flower.com"}
]
}
`),
GetDeployment: Deployment{
ID: "deployment-test-id",
Type: "airflow",
Label: "test deployment",
ReleaseName: "prehistoric-gravity-930",
Version: "2.2.0",
AirflowVersion: "2.2.0",
DesiredAirflowVersion: "2.2.0",
DeploymentInfo: DeploymentInfo{},
Workspace: Workspace{
ID: "test-workspace-id",
},
Urls: []DeploymentURL{
{Type: "airflow", URL: "http://airflow.com"},
{Type: "flower", URL: "http://flower.com"},
},
CreatedAt: time.Time{},
UpdatedAt: time.Time{},
},
},
}
jsonResponse, err := json.Marshal(mockDeployment)
Expand All @@ -291,7 +291,7 @@ func TestGetDeployment(t *testing.T) {

deployment, err := api.GetDeployment("deployment-id")
assert.NoError(t, err)
assert.Equal(t, deployment.ID, "deployment-test-id")
assert.Equal(t, deployment, &mockDeployment.Data.GetDeployment)
})

t.Run("error", func(t *testing.T) {
Expand All @@ -307,28 +307,6 @@ func TestGetDeployment(t *testing.T) {
_, err := api.GetDeployment("deployment-id")
assert.Contains(t, err.Error(), "Internal Server Error")
})

mockDeployment = &Response{
Data: ResponseData{
GetDeployment: []byte(`[]`),
},
}
jsonResponse, err = json.Marshal(mockDeployment)
assert.NoError(t, err)

t.Run("successful query but empty result error", func(t *testing.T) {
client := testUtil.NewTestClient(func(req *http.Request) *http.Response {
return &http.Response{
StatusCode: 200,
Body: io.NopCloser(bytes.NewBuffer(jsonResponse)),
Header: make(http.Header),
}
})
api := NewClient(client)

_, err := api.GetDeployment("deployment-id")
assert.Contains(t, err.Error(), "GetDeployment failed for id:")
})
}

func TestUpdateDeploymentAirflow(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions houston/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package houston

import (
"encoding/json"
"fmt"
"time"

Expand Down Expand Up @@ -31,7 +30,7 @@ type ResponseData struct {
DeleteWorkspaceServiceAccount *ServiceAccount `json:"deleteWorkspaceServiceAccount,omitempty"`
DeleteDeploymentServiceAccount *ServiceAccount `json:"deleteDeploymentServiceAccount,omitempty"`
DeleteWorkspace *Workspace `json:"deleteWorkspace,omitempty"`
GetDeployment json.RawMessage `json:"deployment,omitempty"`
GetDeployment Deployment `json:"deployment,omitempty"`
GetDeployments []Deployment `json:"workspaceDeployments,omitempty"`
GetAuthConfig *AuthConfig `json:"authConfig,omitempty"`
GetAppConfig *AppConfig `json:"appConfig,omitempty"`
Expand Down

0 comments on commit 35f7530

Please sign in to comment.