// SetCharmURL marks the unit as currently using the supplied charm URL.
// An error will be returned if the unit is dead, or the charm URL not known.
497163
func (u *Unit) SetCharmURL(curl *charm.URL) error {
	if curl == nil {
		return fmt.Errorf("cannot set nil charm url")
	}

	db, closer := u.st.newDB()
	defer closer()
	units, closer := db.GetCollection(unitsC)
	defer closer()
	charms, closer := db.GetCollection(charmsC)
	defer closer()

	buildTxn := func(attempt int) ([]txn.Op, error) {
		if attempt > 0 {
			// NOTE: We're explicitly allowing SetCharmURL to succeed
			// when the unit is Dying, because application/charm upgrades
			// should still be allowed to apply to dying units, so
			// that bugs in departed/broken hooks can be addressed at
			// runtime.
			if notDead, err := isNotDeadWithSession(units, u.doc.DocID); err != nil {
				return nil, errors.Trace(err)
			} else if !notDead {
				return nil, ErrDead
			}
		}
		sel := bson.D{{"_id", u.doc.DocID}, {"charmurl", curl}}
		if count, err := units.Find(sel).Count(); err != nil {
			return nil, errors.Trace(err)
		} else if count == 1 {
			// Already set
			return nil, jujutxn.ErrNoOperations
		}
		if count, err := charms.FindId(curl.String()).Count(); err != nil {
			return nil, errors.Trace(err)
		} else if count < 1 {
			return nil, errors.Errorf("unknown charm url %q", curl)
		}

		// Add a reference to the application settings for the new charm.
		incOps, err := appCharmIncRefOps(u.st, u.doc.Application, curl, false)
		if err != nil {
			return nil, errors.Trace(err)
		}

		// Set the new charm URL.
		differentCharm := bson.D{{"charmurl", bson.D{{"$ne", curl}}}}
		ops := append(incOps,
			txn.Op{
				C:      unitsC,
				Id:     u.doc.DocID,
				Assert: append(notDeadDoc, differentCharm...),
				Update: bson.D{{"$set", bson.D{{"charmurl", curl}}}},
			})
		if u.doc.CharmURL != nil {
			// Drop the reference to the old charm.
			// Since we can force this now, let's.. There is no point hanging on to the old charm.
			op := &ForcedOperation{Force: true}
			decOps, err := appCharmDecRefOps(u.st, u.doc.Application, u.doc.CharmURL, true, op)
			if err != nil {
				// No need to stop further processing if the old key could not be removed.
				logger.Errorf("could not remove old charm references for %v:%v", u.doc.CharmURL, err)
			}
			if len(op.Errors) != 0 {
				logger.Errorf("could not remove old charm references for %v:%v", u.doc.CharmURL, op.Errors)
			}
			ops = append(ops, decOps...)
		}
		return ops, nil
	}
	err := u.st.db().Run(buildTxn)
	if err == nil {
		u.doc.CharmURL = curl
	}
	return err
}
451953
func (s *Sample) SetUrl(v string) *Sample {
	s.Url = &v
	return s
}
616672
func (s *DescribeOriginEndpointOutput) SetUrl(v string) *DescribeOriginEndpointOutput {
	s.Url = &v
	return s
}
111329
func (r *Request) SetURL(u *url.URL) *Request {
	r.URLStruct = u
	return r
}
862745
func (s *BundleDetails) SetIconUrl(v string) *BundleDetails {
	s.IconUrl = &v
	return s
}
19796
func (api *APIBase) SetCharm(args params.ApplicationSetCharm) error {
	if err := api.checkCanWrite(); err != nil {
		return err
	}
	// when forced units in error, don't block
	if !args.ForceUnits {
		if err := api.check.ChangeAllowed(); err != nil {
			return errors.Trace(err)
		}
	}
	application, err := api.backend.Application(args.ApplicationName)
	if err != nil {
		return errors.Trace(err)
	}
	channel := csparams.Channel(args.Channel)
	return api.setCharmWithAgentValidation(
		setCharmParams{
			AppName:               args.ApplicationName,
			Application:           application,
			Channel:               channel,
			ConfigSettingsStrings: args.ConfigSettings,
			ConfigSettingsYAML:    args.ConfigSettingsYAML,
			ResourceIDs:           args.ResourceIDs,
			StorageConstraints:    args.StorageConstraints,
			Force: forceParams{
				ForceSeries: args.ForceSeries,
				ForceUnits:  args.ForceUnits,
				Force:       args.Force,
			},
		},
		args.CharmURL,
	)
}
1046633
func (s *Message) SetImageUrl(v string) *Message {
	s.ImageUrl = &v
	return s
}
757160
func (s *StaticKeyProvider) SetUrl(v string) *StaticKeyProvider {
	s.Url = &v
	return s
}
117598
func (s *TagQueueInput) SetQueueUrl(v string) *TagQueueInput {
	s.QueueUrl = &v
	return s
}
1356164
func (s *ADMMessage) SetUrl(v string) *ADMMessage {
	s.Url = &v
	return s
}
435116
func (s *GetExportOutput) SetUrl(v string) *GetExportOutput {
	s.Url = &v
	return s
}
1295108
func (s *SalesforceAction) SetUrl(v string) *SalesforceAction {
	s.Url = &v
	return s
}
589293
func (u *Unit) CharmURL() (*charm.URL, bool) {
	if u.doc.CharmURL == nil {
		return nil, false
	}
	return u.doc.CharmURL, true
}
185541
func (s *EstimateTemplateCostInput) SetTemplateURL(v string) *EstimateTemplateCostInput {
	s.TemplateURL = &v
	return s
}
639966
func (s *InputDestination) SetUrl(v string) *InputDestination {
	s.Url = &v
	return s
}
937263
func (s *GetDashboardEmbedUrlOutput) SetEmbedUrl(v string) *GetDashboardEmbedUrlOutput {
	s.EmbedUrl = &v
	return s
}
615673
func (a *ContinueRequestArgs) SetURL(url string) *ContinueRequestArgs {
	a.URL = &url
	return a
}