// Handle F5 use case: Admin manually creates HostSubnet with 'AssignHostSubnetAnnotation'
// to allocate a subnet with no real node in the cluster.
346732
func (master *OsdnMaster) handleAssignHostSubnetAnnotation(hs *networkapi.HostSubnet) error {
	// Delete the annotated hostsubnet and create a new one with an assigned subnet
	// We do not update (instead of delete+create) because the watchSubnets on the nodes
	// will skip the event if it finds that the hostsubnet has the same host
	// And we cannot fix the watchSubnets code for node because it will break migration if
	// nodes are upgraded after the master
	if err := master.networkClient.NetworkV1().HostSubnets().Delete(hs.Name, &metav1.DeleteOptions{}); err != nil {
		return fmt.Errorf("error in deleting annotated subnet: %s, %v", hs.Name, err)
	}
	klog.Infof("Deleted HostSubnet not backed by node: %s", common.HostSubnetToString(hs))

	var hsAnnotations map[string]string
	if vnid, ok := hs.Annotations[networkapi.FixedVNIDHostAnnotation]; ok {
		vnidInt, err := strconv.Atoi(vnid)
		if err == nil && vnidInt >= 0 && uint32(vnidInt) <= network.MaxVNID {
			hsAnnotations = make(map[string]string)
			hsAnnotations[networkapi.FixedVNIDHostAnnotation] = strconv.Itoa(vnidInt)
		} else {
			utilruntime.HandleError(fmt.Errorf("VNID %s is an invalid value for annotation %s. Annotation will be ignored.", vnid, networkapi.FixedVNIDHostAnnotation))
		}
	}

	if _, err := master.addNode(hs.Name, "", hs.HostIP, hsAnnotations); err != nil {
		return fmt.Errorf("error creating subnet: %s, %v", hs.Name, err)
	}
	klog.Infof("Created HostSubnet not backed by node: %s", common.HostSubnetToString(hs))
	return nil
}
42074
func (r *rpcHandler) handleNomadConn(ctx context.Context, conn net.Conn, server *rpc.Server) {
	defer conn.Close()
	rpcCodec := pool.NewServerCodec(conn)
	for {
		select {
		case <-ctx.Done():
			r.logger.Info("closing server RPC connection")
			return
		case <-r.shutdownCh:
			return
		default:
		}

		if err := server.ServeRequest(rpcCodec); err != nil {
			if err != io.EOF && !strings.Contains(err.Error(), "closed") {
				r.logger.Error("RPC error", "error", err, "connection", conn)
				metrics.IncrCounter([]string{"nomad", "rpc", "request_error"}, 1)
			}
			return
		}
		metrics.IncrCounter([]string{"nomad", "rpc", "request"}, 1)
	}
}
529631
func (f *fs) handleMknod(r *fuse.MknodRequest) {
	log.Println("Inside handleMknod")
	// NOTE: We probably will not need this since we implement Create
	r.RespondError(fuse.EIO)
}
644731
func (h *basicHandler) Handle(c context.Context, conn net.Conn) {
	h.handlerFunc(c, conn)
}
1303427
func HandleFunc(t Type, f func(ResponseWriter, *Request)) {
	DefaultMux.HandleFunc(t, f)
}
1040628
func (n *LegacyNovaNetworking) Subnets(instId instance.Id, subnetIds []network.Id) ([]network.SubnetInfo, error) {
	return nil, errors.NotSupportedf("nova subnet")
}
560451
func (c *Client) handleNomadConn(conn net.Conn) {
	defer conn.Close()
	rpcCodec := pool.NewServerCodec(conn)
	for {
		select {
		case <-c.shutdownCh:
			return
		default:
		}

		if err := c.rpcServer.ServeRequest(rpcCodec); err != nil {
			if err != io.EOF && !strings.Contains(err.Error(), "closed") {
				c.rpcLogger.Error("error performing RPC", "error", err, "addr", conn.RemoteAddr())
				metrics.IncrCounter([]string{"client", "rpc", "request_error"}, 1)
			}
			return
		}
		metrics.IncrCounter([]string{"client", "rpc", "request"}, 1)
	}
}
328345
func (idr *InitDryRunGetter) handleKubernetesService(action core.GetAction) (bool, runtime.Object, error) {
	if action.GetName() != "kubernetes" || action.GetNamespace() != metav1.NamespaceDefault || action.GetResource().Resource != "services" {
		// We can't handle this event
		return false, nil, nil
	}

	_, svcSubnet, err := net.ParseCIDR(idr.serviceSubnet)
	if err != nil {
		return true, nil, errors.Wrapf(err, "error parsing CIDR %q", idr.serviceSubnet)
	}

	internalAPIServerVirtualIP, err := ipallocator.GetIndexedIP(svcSubnet, 1)
	if err != nil {
		return true, nil, errors.Wrapf(err, "unable to get first IP address from the given CIDR (%s)", svcSubnet.String())
	}

	// The only used field of this Service object is the ClusterIP, which kube-dns uses to calculate its own IP
	return true, &v1.Service{
		ObjectMeta: metav1.ObjectMeta{
			Name:      "kubernetes",
			Namespace: metav1.NamespaceDefault,
			Labels: map[string]string{
				"component": "apiserver",
				"provider":  "kubernetes",
			},
		},
		Spec: v1.ServiceSpec{
			ClusterIP: internalAPIServerVirtualIP.String(),
			Ports: []v1.ServicePort{
				{
					Name:       "https",
					Port:       443,
					TargetPort: intstr.FromInt(6443),
				},
			},
		},
	}, nil
}
25695
func (r *Router) HandleFunc(path string, h http.HandlerFunc, ms ...Method) {
	r.Route(
		path,
		func(w http.ResponseWriter, req *Request) error {
			h(w, req.Request)
			return nil
		},
		ms...,
	)
}
824087
func (i *IdentityStore) handleAliasUpdateCommon() framework.OperationFunc {
	return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
		var err error
		var alias *identity.Alias
		var entity *identity.Entity
		var previousEntity *identity.Entity

		i.lock.Lock()
		defer i.lock.Unlock()

		// Check for update or create
		aliasID := d.Get("id").(string)
		if aliasID != "" {
			alias, err = i.MemDBAliasByID(aliasID, true, false)
			if err != nil {
				return nil, err
			}
			if alias == nil {
				return logical.ErrorResponse("invalid alias id"), nil
			}
		} else {
			alias = &identity.Alias{}
		}

		// Get entity id
		canonicalID := d.Get("canonical_id").(string)
		if canonicalID == "" {
			// For backwards compatibility
			canonicalID = d.Get("entity_id").(string)
		}

		// Get alias name
		if aliasName := d.Get("name").(string); aliasName == "" {
			if alias.Name == "" {
				return logical.ErrorResponse("missing alias name"), nil
			}
		} else {
			alias.Name = aliasName
		}

		// Get mount accessor
		if mountAccessor := d.Get("mount_accessor").(string); mountAccessor == "" {
			if alias.MountAccessor == "" {
				return logical.ErrorResponse("missing mount_accessor"), nil
			}
		} else {
			alias.MountAccessor = mountAccessor
		}

		mountValidationResp := i.core.router.validateMountByAccessor(alias.MountAccessor)
		if mountValidationResp == nil {
			return logical.ErrorResponse(fmt.Sprintf("invalid mount accessor %q", alias.MountAccessor)), nil
		}
		if mountValidationResp.MountLocal {
			return logical.ErrorResponse(fmt.Sprintf("mount_accessor %q is of a local mount", alias.MountAccessor)), nil
		}

		// Verify that the combination of alias name and mount is not
		// already tied to a different alias
		aliasByFactors, err := i.MemDBAliasByFactors(mountValidationResp.MountAccessor, alias.Name, false, false)
		if err != nil {
			return nil, err
		}
		if aliasByFactors != nil {
			// If it's a create we won't have an alias ID so this will correctly
			// bail. If it's an update alias will be the same as aliasbyfactors so
			// we don't need to transfer any info over
			if aliasByFactors.ID != alias.ID {
				return logical.ErrorResponse("combination of mount and alias name is already in use"), nil
			}

			// Fetch the entity to which the alias is tied. We don't need to append
			// here, so the only further checking is whether the canonical ID is
			// different
			entity, err = i.MemDBEntityByAliasID(alias.ID, true)
			if err != nil {
				return nil, err
			}
			if entity == nil {
				return nil, fmt.Errorf("existing alias is not associated with an entity")
			}
		} else if alias.ID != "" {
			// This is an update, not a create; if we have an associated entity
			// already, load it
			entity, err = i.MemDBEntityByAliasID(alias.ID, true)
			if err != nil {
				return nil, err
			}
		}

		resp := &logical.Response{}

		// If we found an existing alias we won't hit this condition because
		// canonicalID being empty will result in nil being returned in the block
		// above, so in this case we know that creating a new entity is the right
		// thing.
		if canonicalID == "" {
			entity = &identity.Entity{
				Aliases: []*identity.Alias{
					alias,
				},
			}
		} else {
			// If we can look up by the given canonical ID, see if this is a
			// transfer; otherwise if we found no previous entity but we find one
			// here, use it.
			canonicalEntity, err := i.MemDBEntityByID(canonicalID, true)
			if err != nil {
				return nil, err
			}
			if canonicalEntity == nil {
				return logical.ErrorResponse("invalid canonical ID"), nil
			}
			if entity == nil {
				// If entity is nil, we didn't find a previous alias from factors,
				// so append to this entity
				entity = canonicalEntity
				entity.Aliases = append(entity.Aliases, alias)
			} else if entity.ID != canonicalEntity.ID {
				// In this case we found an entity from alias factors or given
				// alias ID but it's not the same, so it's a migration
				previousEntity = entity
				entity = canonicalEntity

				for aliasIndex, item := range previousEntity.Aliases {
					if item.ID == alias.ID {
						previousEntity.Aliases = append(previousEntity.Aliases[:aliasIndex], previousEntity.Aliases[aliasIndex+1:]...)
						break
					}
				}

				entity.Aliases = append(entity.Aliases, alias)
				resp.AddWarning(fmt.Sprintf("alias is being transferred from entity %q to %q", previousEntity.ID, entity.ID))
			}
		}

		// ID creation and other validations; This is more useful for new entities
		// and may not perform anything for the existing entities. Placing the
		// check here to make the flow common for both new and existing entities.
		err = i.sanitizeEntity(ctx, entity)
		if err != nil {
			return nil, err
		}

		// Explicitly set to empty as in the past we incorrectly saved it
		alias.MountPath = ""
		alias.MountType = ""

		// Set the canonical ID in the alias index. This should be done after
		// sanitizing entity.
		alias.CanonicalID = entity.ID

		// ID creation and other validations
		err = i.sanitizeAlias(ctx, alias)
		if err != nil {
			return nil, err
		}

		for index, item := range entity.Aliases {
			if item.ID == alias.ID {
				entity.Aliases[index] = alias
			}
		}

		// Index entity and its aliases in MemDB and persist entity along with
		// aliases in storage. If the alias is being transferred over from
		// one entity to another, previous entity needs to get refreshed in MemDB
		// and persisted in storage as well.
		if err := i.upsertEntity(ctx, entity, previousEntity, true); err != nil {
			return nil, err
		}

		// Return ID of both alias and entity
		resp.Data = map[string]interface{}{
			"id":           alias.ID,
			"canonical_id": entity.ID,
		}

		return resp, nil
	}
}
357187
func (env *maasEnviron) Subnets(ctx context.ProviderCallContext, instId instance.Id, subnetIds []network.Id) ([]network.SubnetInfo, error) {
	if env.usingMAAS2() {
		return env.subnets2(ctx, instId, subnetIds)
	}
	return env.subnets1(ctx, instId, subnetIds)
}
503382
func Serve(l net.Listener, h Handler, appname, hostname string) (err error) {
  serv := Server{
    Appname: appname,
    Hostname: hostname,
    Handler: h,
  }
  return serv.Serve(l)
}
280890
func HandleAnnotations(mux *http.ServeMux, prefix string, handler AnnotationsHandler) {
	mux.Handle(path.Join("/", prefix, "annotations"), NewAnnotationsHandler(handler))
}
45554
func (s *ServeMux) HandleHost(host, path string, handler http.Handler) {
	s.RouteHost(host, path).Any(handler)
}
1277157
func (st *State) AddSubnet(args SubnetInfo) (subnet *Subnet, err error) {
	defer errors.DeferredAnnotatef(&err, "adding subnet %q", args.CIDR)

	subnet, err = st.newSubnetFromArgs(args)
	if err != nil {
		return nil, errors.Trace(err)
	}
	ops := st.addSubnetOps(args)
	ops = append(ops, assertModelActiveOp(st.ModelUUID()))
	buildTxn := func(attempt int) ([]txn.Op, error) {

		if attempt != 0 {
			if err := checkModelActive(st); err != nil {
				return nil, errors.Trace(err)
			}
			if _, err = st.Subnet(args.CIDR); err == nil {
				return nil, errors.AlreadyExistsf("subnet %q", args.CIDR)
			}
			if err := subnet.Refresh(); err != nil {
				if errors.IsNotFound(err) {
					return nil, errors.Errorf("ProviderId %q not unique", args.ProviderId)
				}
				return nil, errors.Trace(err)
			}
		}
		return ops, nil
	}
	err = st.db().Run(buildTxn)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return subnet, nil
}
1292447
func (s *Server) Handle(addr string, handler HandlerFunc) error {
	if s.Dispatcher == nil {
		s.Dispatcher = NewOscDispatcher()
	}
	return s.Dispatcher.AddMsgHandler(addr, handler)
}
350062
func handleDebugLevel(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
	c := cmd.(*btcjson.DebugLevelCmd)

	// Special show command to list supported subsystems.
	if c.LevelSpec == "show" {
		return fmt.Sprintf("Supported subsystems %v",
			supportedSubsystems()), nil
	}

	err := parseAndSetDebugLevels(c.LevelSpec)
	if err != nil {
		return nil, &btcjson.RPCError{
			Code:    btcjson.ErrRPCInvalidParams.Code,
			Message: err.Error(),
		}
	}

	return "Done.", nil
}