本文整理汇总了Golang中github.com/juju/errors.NewNotFound函数的典型用法代码示例。如果您正苦于以下问题:Golang NewNotFound函数的具体用法?Golang NewNotFound怎么用?Golang NewNotFound使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewNotFound函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: DetectRegions
// DetectRegions implements environs.CloudRegionDetector.
func (EnvironProvider) DetectRegions() ([]cloud.Region, error) {
// If OS_REGION_NAME and OS_AUTH_URL are both set,
// return return a region using them.
creds := identity.CredentialsFromEnv()
if creds.Region == "" {
return nil, errors.NewNotFound(nil, "OS_REGION_NAME environment variable not set")
}
if creds.URL == "" {
return nil, errors.NewNotFound(nil, "OS_AUTH_URL environment variable not set")
}
return []cloud.Region{{
Name: creds.Region,
Endpoint: creds.URL,
}}, nil
}
开发者ID:makyo,项目名称:juju,代码行数:16,代码来源:provider.go
示例2: TestNewResourcePendingResourceOpsNotFound
func (s *PersistenceSuite) TestNewResourcePendingResourceOpsNotFound(c *gc.C) {
pendingID := "some-unique-ID-001"
stored, expected := newResource(c, "a-service", "spam")
stored.PendingID = pendingID
doc := expected // a copy
doc.DocID = pendingResourceID(stored.ID, pendingID)
doc.PendingID = pendingID
s.base.ReturnOne = doc
notFound := errors.NewNotFound(nil, "")
s.stub.SetErrors(nil, notFound)
p := NewPersistence(s.base)
ops, err := p.NewResolvePendingResourceOps(stored.ID, stored.PendingID)
c.Assert(err, jc.ErrorIsNil)
s.stub.CheckCallNames(c, "One", "One")
s.stub.CheckCall(c, 0, "One", "resources", "resource#a-service/spam#pending-some-unique-ID-001", &doc)
c.Check(ops, jc.DeepEquals, []txn.Op{{
C: "resources",
Id: doc.DocID,
Assert: txn.DocExists,
Remove: true,
}, {
C: "resources",
Id: expected.DocID,
Assert: txn.DocMissing,
Insert: &expected,
}})
}
开发者ID:OSBI,项目名称:juju,代码行数:29,代码来源:persistence_test.go
示例3: TestSetResourceNotFound
func (s *ResourcePersistenceSuite) TestSetResourceNotFound(c *gc.C) {
applicationname := "a-application"
res, doc := newPersistenceResource(c, applicationname, "spam")
s.base.ReturnOne = doc
expected := doc // a copy
expected.StoragePath = ""
p := NewResourcePersistence(s.base)
notFound := errors.NewNotFound(nil, "")
ignoredErr := errors.New("<never reached>")
s.stub.SetErrors(notFound, nil, nil, nil, ignoredErr)
err := p.SetResource(res.Resource)
c.Assert(err, jc.ErrorIsNil)
s.stub.CheckCallNames(c,
"One",
"Run",
"ApplicationExistsOps",
"RunTransaction",
)
s.stub.CheckCall(c, 3, "RunTransaction", []txn.Op{{
C: "resources",
Id: "resource#a-application/spam",
Assert: txn.DocMissing,
Insert: &expected,
}, {
C: "application",
Id: "a-application",
Assert: txn.DocExists,
}})
}
开发者ID:bac,项目名称:juju,代码行数:31,代码来源:resources_persistence_test.go
示例4: cancelDeployment
// cancelDeployment cancels a template deployment.
func (env *azureEnviron) cancelDeployment(name string) error {
deploymentsClient := resources.DeploymentsClient{env.resources}
logger.Debugf("- canceling deployment %q", name)
var cancelResult autorest.Response
if err := env.callAPI(func() (autorest.Response, error) {
var err error
cancelResult, err = deploymentsClient.Cancel(env.resourceGroup, name)
return cancelResult, err
}); err != nil {
if cancelResult.Response != nil {
switch cancelResult.StatusCode {
case http.StatusNotFound:
return errors.NewNotFound(err, fmt.Sprintf("deployment %q not found", name))
case http.StatusConflict:
if err, ok := errorutils.ServiceError(err); ok {
if err.Code == serviceErrorCodeDeploymentCannotBeCancelled {
// Deployments can only canceled while they're running.
return nil
}
}
}
}
return errors.Annotatef(err, "canceling deployment %q", name)
}
return nil
}
开发者ID:bac,项目名称:juju,代码行数:27,代码来源:environ.go
示例5: RestoreError
// RestoreError makes a best effort at converting the given error
// back into an error originally converted by ServerError(). If the
// error could not be converted then false is returned.
func RestoreError(err error) (error, bool) {
err = errors.Cause(err)
if apiErr, ok := err.(*params.Error); !ok {
return err, false
} else if apiErr == nil {
return nil, true
}
if params.ErrCode(err) == "" {
return err, false
}
msg := err.Error()
if singleton, ok := singletonError(err); ok {
return singleton, true
}
// TODO(ericsnow) Support the other error types handled by ServerError().
switch {
case params.IsCodeUnauthorized(err):
return errors.NewUnauthorized(nil, msg), true
case params.IsCodeNotFound(err):
// TODO(ericsnow) UnknownModelError should be handled here too.
// ...by parsing msg?
return errors.NewNotFound(nil, msg), true
case params.IsCodeAlreadyExists(err):
return errors.NewAlreadyExists(nil, msg), true
case params.IsCodeNotAssigned(err):
return errors.NewNotAssigned(nil, msg), true
case params.IsCodeHasAssignedUnits(err):
// TODO(ericsnow) Handle state.HasAssignedUnitsError here.
// ...by parsing msg?
return err, false
case params.IsCodeNoAddressSet(err):
// TODO(ericsnow) Handle isNoAddressSetError here.
// ...by parsing msg?
return err, false
case params.IsCodeNotProvisioned(err):
return errors.NewNotProvisioned(nil, msg), true
case params.IsCodeUpgradeInProgress(err):
// TODO(ericsnow) Handle state.UpgradeInProgressError here.
// ...by parsing msg?
return err, false
case params.IsCodeMachineHasAttachedStorage(err):
// TODO(ericsnow) Handle state.HasAttachmentsError here.
// ...by parsing msg?
return err, false
case params.IsCodeNotSupported(err):
return errors.NewNotSupported(nil, msg), true
case params.IsBadRequest(err):
return errors.NewBadRequest(nil, msg), true
case params.IsMethodNotAllowed(err):
return errors.NewMethodNotAllowed(nil, msg), true
case params.ErrCode(err) == params.CodeDischargeRequired:
// TODO(ericsnow) Handle DischargeRequiredError here.
return err, false
default:
return err, false
}
}
开发者ID:exekias,项目名称:juju,代码行数:63,代码来源:errors.go
示例6: getRegion
// getRegion returns the cloud.Region to use, based on the specified
// region name, and the region name selected if none was specified.
//
// If no region name is specified, and there is at least one region,
// we use the first region in the list.
//
// If no region name is specified, and there are no regions at all,
// then we synthesise a region from the cloud's endpoint information
// and just pass this on to the provider.
func getRegion(cloud *jujucloud.Cloud, cloudName, regionName string) (jujucloud.Region, error) {
if len(cloud.Regions) == 0 {
// The cloud does not specify regions, so assume
// that the cloud provider does not have a concept
// of regions, or has no pre-defined regions, and
// defer validation to the provider.
region := jujucloud.Region{
regionName,
cloud.Endpoint,
cloud.StorageEndpoint,
}
return region, nil
}
if regionName == "" {
// No region was specified, use the first region in the list.
return cloud.Regions[0], nil
}
for _, region := range cloud.Regions {
// Do a case-insensitive comparison
if strings.EqualFold(region.Name, regionName) {
return region, nil
}
}
return jujucloud.Region{}, errors.NewNotFound(nil, fmt.Sprintf(
"region %q in cloud %q not found (expected one of %q)\nalternatively, try %q",
regionName, cloudName, cloudRegionNames(cloud), "juju update-clouds",
))
}
开发者ID:makyo,项目名称:juju,代码行数:37,代码来源:bootstrap.go
示例7: detectCredential
func (c OpenstackCredentials) detectCredential() (*cloud.Credential, string, string, error) {
creds := identity.CredentialsFromEnv()
if creds.TenantName == "" {
return nil, "", "", errors.NewNotFound(nil, "OS_TENANT_NAME environment variable not set")
}
if creds.User == "" {
return nil, "", "", errors.NewNotFound(nil, "neither OS_USERNAME nor OS_ACCESS_KEY environment variable not set")
}
if creds.Secrets == "" {
return nil, "", "", errors.NewNotFound(nil, "neither OS_PASSWORD nor OS_SECRET_KEY environment variable not set")
}
user, err := utils.LocalUsername()
if err != nil {
return nil, "", "", errors.Trace(err)
}
// If OS_USERNAME or NOVA_USERNAME is set, assume userpass.
var credential cloud.Credential
if os.Getenv("OS_USERNAME") != "" || os.Getenv("NOVA_USERNAME") != "" {
user = creds.User
credential = cloud.NewCredential(
cloud.UserPassAuthType,
map[string]string{
credAttrUserName: creds.User,
credAttrPassword: creds.Secrets,
credAttrTenantName: creds.TenantName,
credAttrDomainName: creds.DomainName,
},
)
} else {
credential = cloud.NewCredential(
cloud.AccessKeyAuthType,
map[string]string{
credAttrAccessKey: creds.User,
credAttrSecretKey: creds.Secrets,
credAttrTenantName: creds.TenantName,
},
)
}
region := creds.Region
if region == "" {
region = "<unspecified>"
}
credential.Label = fmt.Sprintf("openstack region %q project %q user %q", region, creds.TenantName, user)
return &credential, user, creds.Region, nil
}
开发者ID:kat-co,项目名称:juju,代码行数:47,代码来源:credentials.go
示例8: convertRawAPIError
func convertRawAPIError(err error) error {
if err2, ok := err.(*googleapi.Error); ok {
if err2.Code == http.StatusNotFound {
return errors.NewNotFound(err, "")
}
}
return err
}
开发者ID:imoapps,项目名称:juju,代码行数:8,代码来源:raw.go
示例9: Get
func (s *JoyentStorage) Get(name string) (io.ReadCloser, error) {
b, err := s.manta.GetObject(s.containerName, name)
if err != nil {
return nil, errors.NewNotFound(err, fmt.Sprintf("cannot find %s", name))
}
r := byteCloser{bytes.NewReader(b)}
return r, nil
}
开发者ID:jiasir,项目名称:juju,代码行数:8,代码来源:storage.go
示例10: DeleteContainer
// DeleteContainer deletes the named container from the storage account.
func (s *JoyentStorage) DeleteContainer(containerName string) error {
err := s.manta.DeleteDirectory(containerName)
if err == nil && strings.EqualFold(s.containerName, containerName) {
s.madeContainer = false
}
if je.IsResourceNotFound(err) {
return errors.NewNotFound(err, fmt.Sprintf("cannot delete %s, not found", containerName))
}
return err
}
开发者ID:jiasir,项目名称:juju,代码行数:11,代码来源:storage.go
示例11: VerifyService
// VerifyService implements resource/state.RawState.
func (st rawState) VerifyService(id string) error {
svc, err := st.base.Service(id)
if err != nil {
return errors.Trace(err)
}
if svc.Life() != corestate.Alive {
return errors.NewNotFound(nil, fmt.Sprintf("service %q dying or dead", id))
}
return nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:11,代码来源:state.go
示例12: removeModelUser
// removeModelUser removes a user from the database.
func (st *State) removeModelUser(user names.UserTag) error {
ops := removeModelUserOps(st.ModelUUID(), user)
err := st.runTransaction(ops)
if err == txn.ErrAborted {
err = errors.NewNotFound(nil, fmt.Sprintf("model user %q does not exist", user.Canonical()))
}
if err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:kat-co,项目名称:juju,代码行数:12,代码来源:modeluser.go
示例13: removeControllerUser
// RemoveControllerUser removes a user from the database.
func (st *State) removeControllerUser(user names.UserTag) error {
ops := removeControllerUserOps(st.ControllerUUID(), user)
err := st.runTransaction(ops)
if err == txn.ErrAborted {
err = errors.NewNotFound(nil, fmt.Sprintf("controller user %q does not exist", user.Id()))
}
if err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:bac,项目名称:juju,代码行数:12,代码来源:controlleruser.go
示例14: Provider
func (r *globalProviderRegistry) Provider(providerType string) (EnvironProvider, error) {
if alias, ok := r.aliases[providerType]; ok {
providerType = alias
}
p, ok := r.providers[providerType]
if !ok {
return nil, errors.NewNotFound(
nil, fmt.Sprintf("no registered provider for %q", providerType),
)
}
return p, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:12,代码来源:config.go
示例15: RegionByName
// RegionByName finds the region in the given slice with the
// specified name, with case folding.
func RegionByName(regions []Region, name string) (*Region, error) {
for _, region := range regions {
if !strings.EqualFold(region.Name, name) {
continue
}
return ®ion, nil
}
return nil, errors.NewNotFound(nil, fmt.Sprintf(
"region %q not found (expected one of %q)",
name, RegionNames(regions),
))
}
开发者ID:kat-co,项目名称:juju,代码行数:14,代码来源:clouds.go
示例16: getVPCSubnetIDsForAvailabilityZone
// getVPCSubnetIDsForAvailabilityZone returns a sorted list of subnet IDs, which
// are both in the given vpcID and the given zoneName. If allowedSubnetIDs is
// not empty, the returned list will only contain IDs present there. Returns an
// error satisfying errors.IsNotFound() when no results match.
func getVPCSubnetIDsForAvailabilityZone(
apiClient vpcAPIClient,
vpcID, zoneName string,
allowedSubnetIDs []string,
) ([]string, error) {
allowedSubnets := set.NewStrings(allowedSubnetIDs...)
vpc := &ec2.VPC{Id: vpcID}
subnets, err := getVPCSubnets(apiClient, vpc)
if err != nil && !isVPCNotUsableError(err) {
return nil, errors.Annotatef(err, "cannot get VPC %q subnets", vpcID)
} else if isVPCNotUsableError(err) {
// We're reusing getVPCSubnets(), but not while validating a VPC
// pre-bootstrap, so we should change vpcNotUsableError to a simple
// NotFoundError.
message := fmt.Sprintf("VPC %q has no subnets in AZ %q", vpcID, zoneName)
return nil, errors.NewNotFound(err, message)
}
matchingSubnetIDs := set.NewStrings()
for _, subnet := range subnets {
if subnet.AvailZone != zoneName {
logger.Infof("skipping subnet %q (in VPC %q): not in the chosen AZ %q", subnet.Id, vpcID, zoneName)
continue
}
if !allowedSubnets.IsEmpty() && !allowedSubnets.Contains(subnet.Id) {
logger.Infof("skipping subnet %q (in VPC %q, AZ %q): not matching spaces constraints", subnet.Id, vpcID, zoneName)
continue
}
matchingSubnetIDs.Add(subnet.Id)
}
if matchingSubnetIDs.IsEmpty() {
message := fmt.Sprintf("VPC %q has no subnets in AZ %q", vpcID, zoneName)
return nil, errors.NewNotFound(nil, message)
}
sortedIDs := matchingSubnetIDs.SortedValues()
logger.Infof("found %d subnets in VPC %q matching AZ %q and constraints: %v", len(sortedIDs), vpcID, zoneName, sortedIDs)
return sortedIDs, nil
}
开发者ID:bac,项目名称:juju,代码行数:44,代码来源:environ_vpc.go
示例17: TestNewResourcePendingResourceOpsNotFound
func (s *ResourcePersistenceSuite) TestNewResourcePendingResourceOpsNotFound(c *gc.C) {
pendingID := "some-unique-ID-001"
stored, expected := newPersistenceResource(c, "a-application", "spam")
stored.PendingID = pendingID
doc := expected // a copy
doc.DocID = pendingResourceID(stored.ID, pendingID)
doc.PendingID = pendingID
s.base.ReturnOne = doc
notFound := errors.NewNotFound(nil, "")
s.stub.SetErrors(nil, notFound)
p := NewResourcePersistence(s.base)
// TODO(macgreagoir) We need to keep using time.Now() for now, while we
// have NewResolvePendingResourceOps returning LastPolled based on
// timeNow(). lp:1558657
lastPolled := time.Now().UTC().Round(time.Second)
ops, err := p.NewResolvePendingResourceOps(stored.ID, stored.PendingID)
c.Assert(err, jc.ErrorIsNil)
s.stub.CheckCallNames(c, "One", "One")
s.stub.CheckCall(c, 0, "One", "resources", "resource#a-application/spam#pending-some-unique-ID-001", &doc)
csresourceDoc := expected
csresourceDoc.DocID = "resource#a-application/spam#charmstore"
csresourceDoc.Username = ""
csresourceDoc.Timestamp = coretesting.ZeroTime()
csresourceDoc.StoragePath = ""
csresourceDoc.LastPolled = lastPolled
res := ops[2].Insert.(*resourceDoc)
res.LastPolled = res.LastPolled.Round(time.Second)
c.Check(ops, jc.DeepEquals, []txn.Op{
{
C: "resources",
Id: doc.DocID,
Assert: txn.DocExists,
Remove: true,
}, {
C: "resources",
Id: expected.DocID,
Assert: txn.DocMissing,
Insert: &expected,
},
{
C: "resources",
Id: csresourceDoc.DocID,
Assert: txn.DocMissing,
Insert: &csresourceDoc,
},
})
}
开发者ID:bac,项目名称:juju,代码行数:52,代码来源:resources_persistence_test.go
示例18: deleteResource
// deleteResource deletes a resource with the given name from the resource
// group, using the provided "Deleter". If the resource does not exist, an
// error satisfying errors.IsNotFound will be returned.
func deleteResource(callAPI callAPIFunc, deleter resourceDeleter, resourceGroup, name string) error {
var result autorest.Response
if err := callAPI(func() (autorest.Response, error) {
var err error
result, err = deleter.Delete(resourceGroup, name, nil)
return result, err
}); err != nil {
if result.Response != nil && result.StatusCode == http.StatusNotFound {
return errors.NewNotFound(err, fmt.Sprintf("resource %q not found", name))
}
return errors.Annotate(err, "canceling deployment")
}
return nil
}
开发者ID:bac,项目名称:juju,代码行数:17,代码来源:utils.go
示例19: TestSetUnitResourceNotFound
func (s *ResourcePersistenceSuite) TestSetUnitResourceNotFound(c *gc.C) {
applicationname := "a-application"
unitname := "a-application/0"
res, _ := newPersistenceUnitResource(c, applicationname, unitname, "eggs")
p := NewResourcePersistence(s.base)
notFound := errors.NewNotFound(nil, "")
s.stub.SetErrors(notFound)
err := p.SetUnitResource("a-application/0", res)
s.stub.CheckCallNames(c, "One")
c.Check(err, jc.Satisfies, errors.IsNotFound)
c.Check(err, gc.ErrorMatches, `resource "eggs" not found`)
}
开发者ID:bac,项目名称:juju,代码行数:14,代码来源:resources_persistence_test.go
示例20: TestNewResourcePendingResourceOpsNotFound
func (s *ResourcePersistenceSuite) TestNewResourcePendingResourceOpsNotFound(c *gc.C) {
pendingID := "some-unique-ID-001"
stored, expected := newPersistenceResource(c, "a-service", "spam")
stored.PendingID = pendingID
doc := expected // a copy
doc.DocID = pendingResourceID(stored.ID, pendingID)
doc.PendingID = pendingID
s.base.ReturnOne = doc
notFound := errors.NewNotFound(nil, "")
s.stub.SetErrors(nil, notFound)
p := NewResourcePersistence(s.base)
lastPolled := time.Now().UTC().Round(time.Second)
ops, err := p.NewResolvePendingResourceOps(stored.ID, stored.PendingID)
c.Assert(err, jc.ErrorIsNil)
s.stub.CheckCallNames(c, "One", "One")
s.stub.CheckCall(c, 0, "One", "resources", "resource#a-service/spam#pending-some-unique-ID-001", &doc)
csresourceDoc := expected
csresourceDoc.DocID = "resource#a-service/spam#charmstore"
csresourceDoc.Username = ""
csresourceDoc.Timestamp = time.Time{}
csresourceDoc.StoragePath = ""
csresourceDoc.LastPolled = lastPolled
res := ops[2].Insert.(*resourceDoc)
res.LastPolled = res.LastPolled.Round(time.Second)
c.Check(ops, jc.DeepEquals, []txn.Op{
{
C: "resources",
Id: doc.DocID,
Assert: txn.DocExists,
Remove: true,
}, {
C: "resources",
Id: expected.DocID,
Assert: txn.DocMissing,
Insert: &expected,
},
{
C: "resources",
Id: csresourceDoc.DocID,
Assert: txn.DocMissing,
Insert: &csresourceDoc,
},
})
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:49,代码来源:resources_persistence_test.go
注:本文中的github.com/juju/errors.NewNotFound函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论