github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/actor/v2v3action/application_summary.go (about)

     1  package v2v3action
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/actionerror"
     5  	"code.cloudfoundry.org/cli/actor/v2action"
     6  	"code.cloudfoundry.org/cli/actor/v3action"
     7  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     8  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
     9  )
    10  
    11  type ApplicationSummary struct {
    12  	v3action.ApplicationSummary
    13  	Routes                       v2action.Routes
    14  	ApplicationInstanceWithStats []v2action.ApplicationInstanceWithStats
    15  }
    16  
    17  func (summary ApplicationSummary) GetIsolationSegmentName() (string, bool) {
    18  	if len(summary.ApplicationInstanceWithStats) > 0 && len(summary.ApplicationInstanceWithStats[0].IsolationSegment) > 0 {
    19  		return summary.ApplicationInstanceWithStats[0].IsolationSegment, true
    20  	}
    21  	return "", false
    22  }
    23  
    24  func (actor Actor) GetApplicationSummaryByNameAndSpace(appName string, spaceGUID string, withObfuscatedValues bool) (ApplicationSummary, Warnings, error) {
    25  
    26  	var summary ApplicationSummary
    27  	var allWarnings Warnings
    28  
    29  	v3Summary, warnings, err := actor.V3Actor.GetApplicationSummaryByNameAndSpace(appName, spaceGUID, withObfuscatedValues)
    30  	allWarnings = append(allWarnings, warnings...)
    31  	if err != nil {
    32  		return ApplicationSummary{}, allWarnings, err
    33  	}
    34  	v3Summary.ProcessSummaries.Sort()
    35  	summary.ApplicationSummary = v3Summary
    36  
    37  	routes, routeWarnings, err := actor.V2Actor.GetApplicationRoutes(summary.GUID)
    38  	allWarnings = append(allWarnings, routeWarnings...)
    39  
    40  	// Depending on the version of CC API - a V3 app can exist but the v2 API
    41  	// cannot find it. So the code ignores the error and continues on.
    42  	if _, ok := err.(ccerror.ResourceNotFoundError); err != nil && !ok {
    43  		return ApplicationSummary{}, allWarnings, err
    44  	}
    45  	summary.Routes = routes
    46  
    47  	if summary.State == constant.ApplicationStarted {
    48  		appStats, warnings, err := actor.V2Actor.GetApplicationInstancesWithStatsByApplication(summary.GUID)
    49  		allWarnings = append(allWarnings, warnings...)
    50  		if _, ok := err.(actionerror.ApplicationInstancesNotFoundError); err != nil && !ok {
    51  			return ApplicationSummary{}, allWarnings, err
    52  		}
    53  		summary.ApplicationInstanceWithStats = appStats
    54  	}
    55  
    56  	return summary, allWarnings, nil
    57  }