Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
Fixes review comments
Browse files Browse the repository at this point in the history
- updates an API to delete by space id
- updates an API URL
- fixes test cases
  • Loading branch information
hrishin committed Nov 29, 2018
1 parent 41dd555 commit cc41ea4
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 21 deletions.
32 changes: 30 additions & 2 deletions controller/pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/fabric8-services/fabric8-wit/log"
"github.com/goadesign/goa"
errs "github.com/pkg/errors"
"github.com/satori/go.uuid"
"fmt"
)

// pipeline implements the pipeline resource.
Expand Down Expand Up @@ -49,11 +51,16 @@ func (c *PipelinesController) Delete(ctx *app.DeletePipelinesContext) error {
}

userNS := *k8sSpace.Name
resp, err := osc.DeleteBuildConfig(userNS, map[string]string{"space": ctx.Space})
spacename, err := c.getSpaceNameFromSpaceID(ctx.SpaceID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}

resp, err := osc.DeleteBuildConfig(userNS, map[string]string{"space": *spacename})
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
"space_name": ctx.Space,
"space_name": *spacename,
}, "error occurred while deleting pipeline")
return jsonapi.JSONErrorResponse(ctx, err)
}
Expand All @@ -62,3 +69,24 @@ func (c *PipelinesController) Delete(ctx *app.DeletePipelinesContext) error {

return ctx.OK([]byte{})
}

func (c *PipelinesController) getSpaceNameFromSpaceID(spaceID uuid.UUID) (*string, error) {
// use WIT API to convert Space UUID to Space name
osioclient, err := c.GetAndCheckOSIOClient(c.Context)
if err != nil {
return nil, err
}

osioSpace, err := osioclient.GetSpaceByID(c.Context, spaceID)
fmt.Printf("spcae %#v", osioSpace)

if err != nil {
return nil, errs.Wrapf(err, "unable to convert space UUID %s to space name", spaceID)
}

if osioSpace == nil || osioSpace.Attributes == nil || osioSpace.Attributes.Name == nil {
return nil, errs.Errorf("space UUID %s is not valid a space", spaceID)
}

return osioSpace.Attributes.Name, nil
}
2 changes: 1 addition & 1 deletion controller/platform_clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (g *defaultClientGetter) GetAndCheckOSIOClient(ctx context.Context) (Opensh
witurl, err := url.Parse(witURLStr)
if err != nil {
log.Error(ctx, map[string]interface{}{
"FABRIC8_WIT_API_URL": witURLStr,
"Sada": witURLStr,
"err": err,
}, "cannot parse FABRIC8_WIT_API_URL: %s", witURLStr)
return nil, errs.Wrapf(err, "cannot parse FABRIC8_WIT_API_URL: %s", witURLStr)
Expand Down
7 changes: 3 additions & 4 deletions controller/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,11 @@ func deleteOpenShiftResource(
}

//delete pipelines from the space
spaceLabel := space.Data.Attributes.Name
log.Debug(ctx, map[string]interface{}{"label": spaceLabel}, "deleting pipelines in")
resp, err = cl.DeletePipelines(ctx, client.DeletePipelinesPath(), spaceLabel)
log.Debug(ctx, map[string]interface{}{"label": spaceID}, "deleting pipelines in")
resp, err = cl.DeletePipelines(ctx, client.DeletePipelinesPath(spaceID))

if err != nil {
log.Error(ctx, nil, fmt.Sprintf("error occurred while deleting pipelines from space : %s", spaceLabel))
log.Error(ctx, nil, fmt.Sprintf("error occurred while deleting pipelines from space : %v", spaceID))
}

return nil
Expand Down
2 changes: 2 additions & 0 deletions controller/space_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ func (s *SpaceControllerTestSuite) TestDeleteSpace() {
"http://core/api/deployments/spaces/aec5f659-0680-4633-8599-5f14f1deeabc/applications/testspace1/deployments/run": {},
"http://core/api/deployments/spaces/aec5f659-0680-4633-8599-5f14f1deeabc/applications/testspace2/deployments/stage": {},
"http://core/api/deployments/spaces/aec5f659-0680-4633-8599-5f14f1deeabc/applications/testspace2/deployments/run": {},
"http://core/api/spaces/aec5f659-0680-4633-8599-5f14f1deeabc/pipelines": {},
}

rDeployments, err := recorder.New("../test/data/deployments/deployments_delete_space.ok")
Expand Down Expand Up @@ -481,6 +482,7 @@ func (s *SpaceControllerTestSuite) TestDeleteSpace() {
"http://core/api/deployments/spaces/4d19e0fb-b558-4160-8768-f41cb8169e95/applications/testspace1/deployments/run": {},
"http://core/api/deployments/spaces/4d19e0fb-b558-4160-8768-f41cb8169e95/applications/testspace2/deployments/stage": {},
"http://core/api/deployments/spaces/4d19e0fb-b558-4160-8768-f41cb8169e95/applications/testspace2/deployments/run": {},
"http://core/api/spaces/4d19e0fb-b558-4160-8768-f41cb8169e95/pipelines": {},
}

rDeployments, err := recorder.New("../test/data/deployments/deployments_delete_space.ok-skip-cluster-false")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@
"related": "http:///api/logout"
}
},
"pipelines": {
"links": {
"related": "http:///api/pipelines"
}
},
"render": {
"links": {
"related": "http:///api/render"
Expand Down
7 changes: 2 additions & 5 deletions design/pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

var _ = a.Resource("pipelines", func() {
a.Parent("space")
a.BasePath("/pipelines")

// An auth token is required to call the auth API to get an OpenShift auth token.
Expand All @@ -15,11 +16,7 @@ var _ = a.Resource("pipelines", func() {
a.Routing(
a.DELETE(""),
)
a.Description("Delete pipelines")
a.Params(func() {
a.Param("space", d.String, "Name of the space")
a.Required("space")
})
a.Description("Delete pipelines under given space")
a.Response(d.OK)
a.Response(d.Unauthorized, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,9 @@ interactions:
# headers:
status: 200 OK
code: 200
- request:
url: http://core/api/spaces/4d19e0fb-b558-4160-8768-f41cb8169e95/pipelines
method: DELETE
response:
status: 200OK
code: 200
8 changes: 4 additions & 4 deletions test/data/deployments/deployments_delete_space.ok.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,23 @@ interactions:
status: 200 OK
code: 200
- request:
url: http://core/api/pipelines?space=testspace
url: http://core/api/deployments/spaces/aec5f659-0680-4633-8599-5f14f1deeabc/applications/testspace2/deployments/stage
method: DELETE
response:
# headers:
status: 200 OK
code: 200
- request:
url: http://core/api/deployments/spaces/aec5f659-0680-4633-8599-5f14f1deeabc/applications/testspace2/deployments/stage
url: http://core/api/deployments/spaces/aec5f659-0680-4633-8599-5f14f1deeabc/applications/testspace2/deployments/run
method: DELETE
response:
# headers:
status: 200 OK
code: 200
- request:
url: http://core/api/deployments/spaces/aec5f659-0680-4633-8599-5f14f1deeabc/applications/testspace2/deployments/run
url: http://core/api/spaces/aec5f659-0680-4633-8599-5f14f1deeabc/pipelines
method: DELETE
response:
# headers:
status: 200 OK
code: 200
code: 200

0 comments on commit cc41ea4

Please sign in to comment.