Skip to content

Commit

Permalink
Renamed ApiStatus to ApiResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
Damien Le Berrigaud committed Oct 7, 2013
1 parent 8b6bc5a commit c4048cd
Show file tree
Hide file tree
Showing 88 changed files with 914 additions and 914 deletions.
10 changes: 5 additions & 5 deletions src/cf/api/app_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type AppFilesRepository interface {
ListFiles(app cf.Application, path string) (files string, apiStatus net.ApiStatus)
ListFiles(app cf.Application, path string) (files string, apiResponse net.ApiResponse)
}

type CloudControllerAppFilesRepository struct {
Expand All @@ -22,13 +22,13 @@ func NewCloudControllerAppFilesRepository(config *configuration.Configuration, g
return
}

func (repo CloudControllerAppFilesRepository) ListFiles(app cf.Application, path string) (files string, apiStatus net.ApiStatus) {
func (repo CloudControllerAppFilesRepository) ListFiles(app cf.Application, path string) (files string, apiResponse net.ApiResponse) {
url := fmt.Sprintf("%s/v2/apps/%s/instances/0/files/%s", repo.config.Target, app.Guid, path)
request, apiStatus := repo.gateway.NewRequest("GET", url, repo.config.AccessToken, nil)
if apiStatus.IsNotSuccessful() {
request, apiResponse := repo.gateway.NewRequest("GET", url, repo.config.AccessToken, nil)
if apiResponse.IsNotSuccessful() {
return
}

files, _, apiStatus = repo.gateway.PerformRequestForTextResponse(request)
files, _, apiResponse = repo.gateway.PerformRequestForTextResponse(request)
return
}
28 changes: 14 additions & 14 deletions src/cf/api/app_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type AppSummaryRepository interface {
GetSummary(app cf.Application) (summary cf.AppSummary, apiStatus net.ApiStatus)
GetSummary(app cf.Application) (summary cf.AppSummary, apiResponse net.ApiResponse)
}

type CloudControllerAppSummaryRepository struct {
Expand All @@ -25,16 +25,16 @@ func NewCloudControllerAppSummaryRepository(config *configuration.Configuration,
return
}

func (repo CloudControllerAppSummaryRepository) GetSummary(app cf.Application) (summary cf.AppSummary, apiStatus net.ApiStatus) {
func (repo CloudControllerAppSummaryRepository) GetSummary(app cf.Application) (summary cf.AppSummary, apiResponse net.ApiResponse) {
summary.App = app

instances, apiStatus := repo.appRepo.GetInstances(app)
if apiStatus.IsNotSuccessful() {
instances, apiResponse := repo.appRepo.GetInstances(app)
if apiResponse.IsNotSuccessful() {
return
}

instances, apiStatus = repo.updateInstancesWithStats(app, instances)
if apiStatus.IsNotSuccessful() {
instances, apiResponse = repo.updateInstancesWithStats(app, instances)
if apiResponse.IsNotSuccessful() {
return
}

Expand All @@ -57,22 +57,22 @@ type InstanceStatsApiResponse struct {
}
}

func (repo CloudControllerAppSummaryRepository) updateInstancesWithStats(app cf.Application, instances []cf.ApplicationInstance) (updatedInst []cf.ApplicationInstance, apiStatus net.ApiStatus) {
func (repo CloudControllerAppSummaryRepository) updateInstancesWithStats(app cf.Application, instances []cf.ApplicationInstance) (updatedInst []cf.ApplicationInstance, apiResponse net.ApiResponse) {
path := fmt.Sprintf("%s/v2/apps/%s/stats", repo.config.Target, app.Guid)
request, apiStatus := repo.gateway.NewRequest("GET", path, repo.config.AccessToken, nil)
if apiStatus.IsNotSuccessful() {
request, apiResponse := repo.gateway.NewRequest("GET", path, repo.config.AccessToken, nil)
if apiResponse.IsNotSuccessful() {
return
}

apiResponse := StatsApiResponse{}
statsResponse := StatsApiResponse{}

_, apiStatus = repo.gateway.PerformRequestForJSONResponse(request, &apiResponse)
if apiStatus.IsNotSuccessful() {
_, apiResponse = repo.gateway.PerformRequestForJSONResponse(request, &statsResponse)
if apiResponse.IsNotSuccessful() {
return
}

updatedInst = make([]cf.ApplicationInstance, len(apiResponse), len(apiResponse))
for k, v := range apiResponse {
updatedInst = make([]cf.ApplicationInstance, len(statsResponse), len(statsResponse))
for k, v := range statsResponse {
index, err := strconv.Atoi(k)
if err != nil {
continue
Expand Down
46 changes: 23 additions & 23 deletions src/cf/api/application_bits.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

type ApplicationBitsRepository interface {
UploadApp(app cf.Application, dir string) (apiStatus net.ApiStatus)
UploadApp(app cf.Application, dir string) (apiResponse net.ApiResponse)
}

type CloudControllerApplicationBitsRepository struct {
Expand All @@ -33,9 +33,9 @@ func NewCloudControllerApplicationBitsRepository(config *configuration.Configura
return
}

func (repo CloudControllerApplicationBitsRepository) UploadApp(app cf.Application, dir string) (apiStatus net.ApiStatus) {
dir, resourcesJson, apiStatus := repo.createUploadDir(app, dir)
if apiStatus.IsNotSuccessful() {
func (repo CloudControllerApplicationBitsRepository) UploadApp(app cf.Application, dir string) (apiResponse net.ApiResponse) {
dir, resourcesJson, apiResponse := repo.createUploadDir(app, dir)
if apiResponse.IsNotSuccessful() {
return
}

Expand All @@ -44,55 +44,55 @@ func (repo CloudControllerApplicationBitsRepository) UploadApp(app cf.Applicatio
return
}

apiStatus = repo.uploadBits(app, zipBuffer, resourcesJson)
if apiStatus.IsNotSuccessful() {
apiResponse = repo.uploadBits(app, zipBuffer, resourcesJson)
if apiResponse.IsNotSuccessful() {
return
}

return
}

func (repo CloudControllerApplicationBitsRepository) uploadBits(app cf.Application, zipBuffer *bytes.Buffer, resourcesJson []byte) (apiStatus net.ApiStatus) {
func (repo CloudControllerApplicationBitsRepository) uploadBits(app cf.Application, zipBuffer *bytes.Buffer, resourcesJson []byte) (apiResponse net.ApiResponse) {
url := fmt.Sprintf("%s/v2/apps/%s/bits", repo.config.Target, app.Guid)

body, boundary, err := createApplicationUploadBody(zipBuffer, resourcesJson)
if err != nil {
apiStatus = net.NewApiStatusWithError("Error creating upload", err)
apiResponse = net.NewApiStatusWithError("Error creating upload", err)
return
}

request, apiStatus := repo.gateway.NewRequest("PUT", url, repo.config.AccessToken, body)
request, apiResponse := repo.gateway.NewRequest("PUT", url, repo.config.AccessToken, body)
contentType := fmt.Sprintf("multipart/form-data; boundary=%s", boundary)
request.Header.Set("Content-Type", contentType)
if apiStatus.IsNotSuccessful() {
if apiResponse.IsNotSuccessful() {
return
}

apiStatus = repo.gateway.PerformRequest(request)
apiResponse = repo.gateway.PerformRequest(request)
return
}

func (repo CloudControllerApplicationBitsRepository) createUploadDir(app cf.Application, appDir string) (uploadDir string, resourcesJson []byte, apiStatus net.ApiStatus) {
func (repo CloudControllerApplicationBitsRepository) createUploadDir(app cf.Application, appDir string) (uploadDir string, resourcesJson []byte, apiResponse net.ApiResponse) {
var err error

// If appDir is a zip, first extract it to a temporary directory
if fileIsZip(appDir) {
appDir, err = extractZip(app, appDir)
if err != nil {
apiStatus = net.NewApiStatusWithError("Error extracting archive", err)
apiResponse = net.NewApiStatusWithError("Error extracting archive", err)
return
}
}

// Find which files need to be uploaded
allAppFiles, err := cf.AppFilesInDir(appDir)
if err != nil {
apiStatus = net.NewApiStatusWithError("Error listing app files", err)
apiResponse = net.NewApiStatusWithError("Error listing app files", err)
return
}

appFilesToUpload, resourcesJson, apiStatus := repo.getFilesToUpload(allAppFiles)
if apiStatus.IsNotSuccessful() {
appFilesToUpload, resourcesJson, apiResponse := repo.getFilesToUpload(allAppFiles)
if apiResponse.IsNotSuccessful() {
return
}

Expand All @@ -101,13 +101,13 @@ func (repo CloudControllerApplicationBitsRepository) createUploadDir(app cf.Appl

err = cf.InitializeDir(uploadDir)
if err != nil {
apiStatus = net.NewApiStatusWithError("Error creating upload directory", err)
apiResponse = net.NewApiStatusWithError("Error creating upload directory", err)
return
}

err = cf.CopyFiles(appFilesToUpload, appDir, uploadDir)
if err != nil {
apiStatus = net.NewApiStatusWithError("Error copying files to temp directory", err)
apiResponse = net.NewApiStatusWithError("Error copying files to temp directory", err)
return
}

Expand Down Expand Up @@ -173,7 +173,7 @@ func extractZip(app cf.Application, zipFile string) (destDir string, err error)
return
}

func (repo CloudControllerApplicationBitsRepository) getFilesToUpload(allAppFiles []cf.AppFile) (appFilesToUpload []cf.AppFile, resourcesJson []byte, apiStatus net.ApiStatus) {
func (repo CloudControllerApplicationBitsRepository) getFilesToUpload(allAppFiles []cf.AppFile) (appFilesToUpload []cf.AppFile, resourcesJson []byte, apiResponse net.ApiResponse) {
appFilesRequest := []AppFile{}
for _, file := range allAppFiles {
appFilesRequest = append(appFilesRequest, AppFile{
Expand All @@ -185,18 +185,18 @@ func (repo CloudControllerApplicationBitsRepository) getFilesToUpload(allAppFile

resourcesJson, err := json.Marshal(appFilesRequest)
if err != nil {
apiStatus = net.NewApiStatusWithError("Failed to create json for resource_match request", err)
apiResponse = net.NewApiStatusWithError("Failed to create json for resource_match request", err)
return
}

path := fmt.Sprintf("%s/v2/resource_match", repo.config.Target)
req, apiStatus := repo.gateway.NewRequest("PUT", path, repo.config.AccessToken, bytes.NewReader(resourcesJson))
if apiStatus.IsNotSuccessful() {
req, apiResponse := repo.gateway.NewRequest("PUT", path, repo.config.AccessToken, bytes.NewReader(resourcesJson))
if apiResponse.IsNotSuccessful() {
return
}

res := []AppFile{}
_, apiStatus = repo.gateway.PerformRequestForJSONResponse(req, &res)
_, apiResponse = repo.gateway.PerformRequestForJSONResponse(req, &res)

appFilesToUpload = make([]cf.AppFile, len(allAppFiles))
copy(appFilesToUpload, allAppFiles)
Expand Down
4 changes: 2 additions & 2 deletions src/cf/api/application_bits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ func testUploadApp(t *testing.T, dir string) {

app := cf.Application{Name: "my-cool-app", Guid: "my-cool-app-guid"}

apiStatus := repo.UploadApp(app, dir)
assert.False(t, apiStatus.IsNotSuccessful())
apiResponse := repo.UploadApp(app, dir)
assert.False(t, apiResponse.IsNotSuccessful())

uploadDir := cf.TempDirForApp(app)
files, err := filepath.Glob(filepath.Join(uploadDir, "*"))
Expand Down
Loading

0 comments on commit c4048cd

Please sign in to comment.