//Recover a destroyed instance with the specified id in the current environment
//Note: Cannot recover instances that have been purged
189775
func (instanceApi *InstanceApi) Recover(id string) (bool, error) {
	_, err := instanceApi.entityService.Execute(id, INSTANCE_RECOVER_OPERATION, []byte{}, map[string]string{})
	return err == nil, err
}
975984
func (c *Cloud) getInstanceByID(instanceID string) (*ec2.Instance, error) {
	instances, err := c.getInstancesByIDs([]*string{&instanceID})
	if err != nil {
		return nil, err
	}

	if len(instances) == 0 {
		return nil, cloudprovider.ErrInstanceNotFound
	}
	if len(instances) > 1 {
		return nil, fmt.Errorf("multiple instances found for instance: %s", instanceID)
	}

	return instances[instanceID], nil
}
461357
func (i *environInstance) Id() instance.Id {
	return instance.Id(i.container.Name)
}
502191
func (cs *clientStore) recoverClients(clients []*stores.Client) {
	cs.Lock()
	for _, sc := range clients {
		client := &client{info: sc, subs: make([]*subState, 0, 4)}
		cs.clients[client.info.ID] = client
		if len(client.info.ConnID) > 0 {
			cs.connIDs[string(client.info.ConnID)] = client
		}
	}
	cs.Unlock()
}
32229
func InstanceID(ctx context.Context) (*types.InstanceID, bool) {
	v, ok := ctx.Value(InstanceIDKey).(*types.InstanceID)
	return v, ok
}
772958
func (instanceApi *InstanceApi) Purge(id string) (bool, error) {
	_, err := instanceApi.entityService.Execute(id, INSTANCE_PURGE_OPERATION, []byte{}, map[string]string{})
	return err == nil, err
}
1218074
func (c *client) Restore(ctx context.Context, id string, attachStdio libcontainerdtypes.StdioCallback) (bool, int, libcontainerdtypes.Process, error) {
	c.logger.WithField("container", id).Debug("restore()")

	// TODO Windows: On RS1, a re-attach isn't possible.
	// However, there is a scenario in which there is an issue.
	// Consider a background container. The daemon dies unexpectedly.
	// HCS will still have the compute service alive and running.
	// For consistence, we call in to shoot it regardless if HCS knows about it
	// We explicitly just log a warning if the terminate fails.
	// Then we tell the backend the container exited.
	if hc, err := hcsshim.OpenContainer(id); err == nil {
		const terminateTimeout = time.Minute * 2
		err := hc.Terminate()

		if hcsshim.IsPending(err) {
			err = hc.WaitTimeout(terminateTimeout)
		} else if hcsshim.IsAlreadyStopped(err) {
			err = nil
		}

		if err != nil {
			c.logger.WithField("container", id).WithError(err).Debug("terminate failed on restore")
			return false, -1, nil, err
		}
	}
	return false, -1, &restoredProcess{
		c:  c,
		id: id,
	}, nil
}
571500
func (c *Client) RetrieveRecord(domain string, id string) (*Record, error) {
	params := make(map[string]string)
	// The zone we want
	params["z"] = domain
	params["id"] = id

	req, err := c.NewRequest(params, "GET", "rec_load_all")

	if err != nil {
		return nil, err
	}

	resp, err := checkResp(c.Http.Do(req))
	if err != nil {
		return nil, fmt.Errorf("Error retrieving record: %s", err)
	}

	records := new(RecordsResponse)

	err = decodeBody(resp, records)

	if err != nil {
		return nil, fmt.Errorf("Error decoding record response: %s", err)
	}

	record, err := records.FindRecord(id)
	if err != nil {
		return nil, err
	}

	// The request was successful
	return record, nil
}
1038896
func (c *Client) RestoreSnapshot(id, snapshotID string) error {
	values := url.Values{
		"SUBID":      {id},
		"SNAPSHOTID": {snapshotID},
	}

	if err := c.post(`server/restore_snapshot`, values, nil); err != nil {
		return err
	}
	return nil
}
331089
func (s *StorageOverseer) Regenerate(w http.ResponseWriter, r *http.Request) error {
	id, err := s.options.getCookieValue(w, r)
	if err != nil {
		return errors.Wrap(err, "unable to get session id from cookie")
	}

	val, err := s.Storer.Get(id)
	if err != nil {
		return errors.Wrap(err, "unable to get session value")
	}

	// Delete the old session
	_ = s.Storer.Del(id)

	// Generate a new ID
	id = uuid.NewV4().String()

	// Create a new session with the old value
	if err = s.Storer.Set(id, val); err != nil {
		return errors.Wrap(err, "unable to set session value")
	}

	// Override the old cookie with the new cookie
	w.(cookieWriter).SetCookie(s.options.makeCookie(id))

	return nil
}
775949
func (p *MemProvider) Regenerate(oldsid, sid string) (RawStore, error) {
	if p.Exist(sid) {
		return nil, fmt.Errorf("new sid '%s' already exists", sid)
	}

	s, err := p.Read(oldsid)
	if err != nil {
		return nil, err
	}

	if err = p.Destory(oldsid); err != nil {
		return nil, err
	}

	s.(*MemStore).sid = sid

	p.lock.Lock()
	defer p.lock.Unlock()
	p.data[sid] = p.list.PushBack(s)
	return s, nil
}
1174456
func (svmMap *serviceVMMap) deleteID(id string) error {
	svmMap.Lock()
	defer svmMap.Unlock()
	svm, ok := svmMap.svms[id]
	if !ok {
		return errVMUnknown
	}
	if svm.refCount != 0 {
		return errVMStillHasReference
	}
	delete(svmMap.svms, id)
	return nil
}
554636
func (p *FileProvider) Regenerate(oldsid, sid string) (_ RawStore, err error) {
	if err := p.regenerate(oldsid, sid); err != nil {
		return nil, err
	}

	return p.Read(sid)
}
440775
func (m Middleware) Recover(next http.Handler) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {
		defer func() {
			if err := recover(); err != nil {
				var protocol string
				if r.TLS == nil {
					protocol = "http"
				} else {
					protocol = "https"
				}

				var log *zap.Logger
				v := r.Context().Value(CtxLoggerKey)
				if v != nil {
					var ok bool
					log, ok = v.(*zap.Logger)
					if !ok {
						panic("cannot get derived request id logger from context object")
					}
					// log with the request_id scoped logger
					log.Error(fmt.Sprintf("%s request error", protocol),
						zap.String("method", r.Method),
						zap.String("uri", r.RequestURI),
						zap.Bool("tls", r.TLS != nil),
						zap.String("protocol", r.Proto),
						zap.String("host", r.Host),
						zap.String("remote_addr", r.RemoteAddr),
						zap.String("error", fmt.Sprintf("%+v", err)),
					)
				} else {
					// log with the logger attached to middleware struct if
					// cannot find request_id scoped logger
					m.Log.Error(fmt.Sprintf("%s request error", protocol),
						zap.String("method", r.Method),
						zap.String("uri", r.RequestURI),
						zap.Bool("tls", r.TLS != nil),
						zap.String("protocol", r.Proto),
						zap.String("host", r.Host),
						zap.String("remote_addr", r.RemoteAddr),
						zap.String("error", fmt.Sprintf("%+v", err)),
					)
				}

				// Return a http 500 with the HTTP body of "Internal Server Error"
				http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
			}
		}()

		next.ServeHTTP(w, r)
	}

	return http.HandlerFunc(fn)
}
1168743
func extractSystemId(instanceId instance.Id) string {
	trimmed := strings.TrimRight(string(instanceId), "/")
	split := strings.Split(trimmed, "/")
	return split[len(split)-1]
}
305459
func (engine *Engine) Id(id interface{}) *Session {
	session := engine.NewSession()
	session.isAutoClose = true
	return session.Id(id)
}
265230
func (p *MemcacheProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err error) {
	if p.Exist(sid) {
		return nil, fmt.Errorf("new sid '%s' already exists", sid)
	}

	item := NewItem(sid, []byte(""), p.expire)
	if p.Exist(oldsid) {
		item, err = p.c.Get(oldsid)
		if err != nil {
			return nil, err
		} else if err = p.c.Delete(oldsid); err != nil {
			return nil, err
		}
		item.Key = sid
	}
	if err = p.c.Set(item); err != nil {
		return nil, err
	}

	var kv map[interface{}]interface{}
	if len(item.Value) == 0 {
		kv = make(map[interface{}]interface{})
	} else {
		kv, err = session.DecodeGob(item.Value)
		if err != nil {
			return nil, err
		}
	}

	return NewMemcacheStore(p.c, sid, p.expire, kv), nil
}