id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
16,000
mdlayher/dhcp6
dhcp6opts/iapd.go
MarshalBinary
func (i *IAPD) MarshalBinary() ([]byte, error) { // 4 bytes: IAID // 4 bytes: T1 // 4 bytes: T2 // N bytes: options slice byte count buf := buffer.New(nil) buf.WriteBytes(i.IAID[:]) buf.Write32(uint32(i.T1 / time.Second)) buf.Write32(uint32(i.T2 / time.Second)) opts, err := i.Options.MarshalBinary() if err != nil { return nil, err } buf.WriteBytes(opts) return buf.Data(), nil }
go
func (i *IAPD) MarshalBinary() ([]byte, error) { // 4 bytes: IAID // 4 bytes: T1 // 4 bytes: T2 // N bytes: options slice byte count buf := buffer.New(nil) buf.WriteBytes(i.IAID[:]) buf.Write32(uint32(i.T1 / time.Second)) buf.Write32(uint32(i.T2 / time.Second)) opts, err := i.Options.MarshalBinary() if err != nil { return nil, err } buf.WriteBytes(opts) return buf.Data(), nil }
[ "func", "(", "i", "*", "IAPD", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// 4 bytes: IAID", "// 4 bytes: T1", "// 4 bytes: T2", "// N bytes: options slice byte count", "buf", ":=", "buffer", ".", "New", "(", "nil", ")", "\n\n", "buf", ".", "WriteBytes", "(", "i", ".", "IAID", "[", ":", "]", ")", "\n", "buf", ".", "Write32", "(", "uint32", "(", "i", ".", "T1", "/", "time", ".", "Second", ")", ")", "\n", "buf", ".", "Write32", "(", "uint32", "(", "i", ".", "T2", "/", "time", ".", "Second", ")", ")", "\n", "opts", ",", "err", ":=", "i", ".", "Options", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "buf", ".", "WriteBytes", "(", "opts", ")", "\n\n", "return", "buf", ".", "Data", "(", ")", ",", "nil", "\n", "}" ]
// MarshalBinary allocates a byte slice containing the data from a IAPD.
[ "MarshalBinary", "allocates", "a", "byte", "slice", "containing", "the", "data", "from", "a", "IAPD", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/iapd.go#L53-L70
16,001
mdlayher/dhcp6
dhcp6opts/iapd.go
UnmarshalBinary
func (i *IAPD) UnmarshalBinary(b []byte) error { // IAPD must contain at least an IAID, T1, and T2. buf := buffer.New(b) if buf.Len() < 12 { return io.ErrUnexpectedEOF } copy(i.IAID[:], buf.Consume(4)) i.T1 = time.Duration(buf.Read32()) * time.Second i.T2 = time.Duration(buf.Read32()) * time.Second return (&i.Options).UnmarshalBinary(buf.Remaining()) }
go
func (i *IAPD) UnmarshalBinary(b []byte) error { // IAPD must contain at least an IAID, T1, and T2. buf := buffer.New(b) if buf.Len() < 12 { return io.ErrUnexpectedEOF } copy(i.IAID[:], buf.Consume(4)) i.T1 = time.Duration(buf.Read32()) * time.Second i.T2 = time.Duration(buf.Read32()) * time.Second return (&i.Options).UnmarshalBinary(buf.Remaining()) }
[ "func", "(", "i", "*", "IAPD", ")", "UnmarshalBinary", "(", "b", "[", "]", "byte", ")", "error", "{", "// IAPD must contain at least an IAID, T1, and T2.", "buf", ":=", "buffer", ".", "New", "(", "b", ")", "\n", "if", "buf", ".", "Len", "(", ")", "<", "12", "{", "return", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n\n", "copy", "(", "i", ".", "IAID", "[", ":", "]", ",", "buf", ".", "Consume", "(", "4", ")", ")", "\n", "i", ".", "T1", "=", "time", ".", "Duration", "(", "buf", ".", "Read32", "(", ")", ")", "*", "time", ".", "Second", "\n", "i", ".", "T2", "=", "time", ".", "Duration", "(", "buf", ".", "Read32", "(", ")", ")", "*", "time", ".", "Second", "\n\n", "return", "(", "&", "i", ".", "Options", ")", ".", "UnmarshalBinary", "(", "buf", ".", "Remaining", "(", ")", ")", "\n", "}" ]
// UnmarshalBinary unmarshals a raw byte slice into a IAPD. // // If the byte slice does not contain enough data to form a valid IAPD, // io.ErrUnexpectedEOF is returned.
[ "UnmarshalBinary", "unmarshals", "a", "raw", "byte", "slice", "into", "a", "IAPD", ".", "If", "the", "byte", "slice", "does", "not", "contain", "enough", "data", "to", "form", "a", "valid", "IAPD", "io", ".", "ErrUnexpectedEOF", "is", "returned", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/iapd.go#L76-L88
16,002
mdlayher/dhcp6
dhcp6opts/relaymessage.go
MarshalBinary
func (rm *RelayMessage) MarshalBinary() ([]byte, error) { // 1 byte: message type // 1 byte: hop-count // 16 bytes: link-address // 16 bytes: peer-address // N bytes: options slice byte count b := buffer.New(nil) b.Write8(uint8(rm.MessageType)) b.Write8(rm.HopCount) copy(b.WriteN(net.IPv6len), rm.LinkAddress) copy(b.WriteN(net.IPv6len), rm.PeerAddress) opts, err := rm.Options.MarshalBinary() if err != nil { return nil, err } b.WriteBytes(opts) return b.Data(), nil }
go
func (rm *RelayMessage) MarshalBinary() ([]byte, error) { // 1 byte: message type // 1 byte: hop-count // 16 bytes: link-address // 16 bytes: peer-address // N bytes: options slice byte count b := buffer.New(nil) b.Write8(uint8(rm.MessageType)) b.Write8(rm.HopCount) copy(b.WriteN(net.IPv6len), rm.LinkAddress) copy(b.WriteN(net.IPv6len), rm.PeerAddress) opts, err := rm.Options.MarshalBinary() if err != nil { return nil, err } b.WriteBytes(opts) return b.Data(), nil }
[ "func", "(", "rm", "*", "RelayMessage", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// 1 byte: message type", "// 1 byte: hop-count", "// 16 bytes: link-address", "// 16 bytes: peer-address", "// N bytes: options slice byte count", "b", ":=", "buffer", ".", "New", "(", "nil", ")", "\n\n", "b", ".", "Write8", "(", "uint8", "(", "rm", ".", "MessageType", ")", ")", "\n", "b", ".", "Write8", "(", "rm", ".", "HopCount", ")", "\n", "copy", "(", "b", ".", "WriteN", "(", "net", ".", "IPv6len", ")", ",", "rm", ".", "LinkAddress", ")", "\n", "copy", "(", "b", ".", "WriteN", "(", "net", ".", "IPv6len", ")", ",", "rm", ".", "PeerAddress", ")", "\n", "opts", ",", "err", ":=", "rm", ".", "Options", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "b", ".", "WriteBytes", "(", "opts", ")", "\n\n", "return", "b", ".", "Data", "(", ")", ",", "nil", "\n", "}" ]
// MarshalBinary allocates a byte slice containing the data // from a RelayMessage.
[ "MarshalBinary", "allocates", "a", "byte", "slice", "containing", "the", "data", "from", "a", "RelayMessage", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/relaymessage.go#L41-L60
16,003
mdlayher/dhcp6
dhcp6opts/relaymessage.go
UnmarshalBinary
func (rm *RelayMessage) UnmarshalBinary(p []byte) error { b := buffer.New(p) // RelayMessage must contain at least message type, hop-count, link-address and peer-address if b.Len() < 34 { return io.ErrUnexpectedEOF } rm.MessageType = dhcp6.MessageType(b.Read8()) rm.HopCount = b.Read8() rm.LinkAddress = make(net.IP, net.IPv6len) copy(rm.LinkAddress, b.Consume(net.IPv6len)) rm.PeerAddress = make(net.IP, net.IPv6len) copy(rm.PeerAddress, b.Consume(net.IPv6len)) if err := (&rm.Options).UnmarshalBinary(b.Remaining()); err != nil { // Invalid options means an invalid RelayMessage return dhcp6.ErrInvalidPacket } return nil }
go
func (rm *RelayMessage) UnmarshalBinary(p []byte) error { b := buffer.New(p) // RelayMessage must contain at least message type, hop-count, link-address and peer-address if b.Len() < 34 { return io.ErrUnexpectedEOF } rm.MessageType = dhcp6.MessageType(b.Read8()) rm.HopCount = b.Read8() rm.LinkAddress = make(net.IP, net.IPv6len) copy(rm.LinkAddress, b.Consume(net.IPv6len)) rm.PeerAddress = make(net.IP, net.IPv6len) copy(rm.PeerAddress, b.Consume(net.IPv6len)) if err := (&rm.Options).UnmarshalBinary(b.Remaining()); err != nil { // Invalid options means an invalid RelayMessage return dhcp6.ErrInvalidPacket } return nil }
[ "func", "(", "rm", "*", "RelayMessage", ")", "UnmarshalBinary", "(", "p", "[", "]", "byte", ")", "error", "{", "b", ":=", "buffer", ".", "New", "(", "p", ")", "\n", "// RelayMessage must contain at least message type, hop-count, link-address and peer-address", "if", "b", ".", "Len", "(", ")", "<", "34", "{", "return", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n\n", "rm", ".", "MessageType", "=", "dhcp6", ".", "MessageType", "(", "b", ".", "Read8", "(", ")", ")", "\n", "rm", ".", "HopCount", "=", "b", ".", "Read8", "(", ")", "\n\n", "rm", ".", "LinkAddress", "=", "make", "(", "net", ".", "IP", ",", "net", ".", "IPv6len", ")", "\n", "copy", "(", "rm", ".", "LinkAddress", ",", "b", ".", "Consume", "(", "net", ".", "IPv6len", ")", ")", "\n\n", "rm", ".", "PeerAddress", "=", "make", "(", "net", ".", "IP", ",", "net", ".", "IPv6len", ")", "\n", "copy", "(", "rm", ".", "PeerAddress", ",", "b", ".", "Consume", "(", "net", ".", "IPv6len", ")", ")", "\n\n", "if", "err", ":=", "(", "&", "rm", ".", "Options", ")", ".", "UnmarshalBinary", "(", "b", ".", "Remaining", "(", ")", ")", ";", "err", "!=", "nil", "{", "// Invalid options means an invalid RelayMessage", "return", "dhcp6", ".", "ErrInvalidPacket", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary unmarshals a raw byte slice into a RelayMessage. // // If the byte slice does not contain enough data to form a valid RelayMessage, // ErrInvalidPacket is returned.
[ "UnmarshalBinary", "unmarshals", "a", "raw", "byte", "slice", "into", "a", "RelayMessage", ".", "If", "the", "byte", "slice", "does", "not", "contain", "enough", "data", "to", "form", "a", "valid", "RelayMessage", "ErrInvalidPacket", "is", "returned", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/relaymessage.go#L66-L87
16,004
mdlayher/dhcp6
dhcp6opts/authentication.go
MarshalBinary
func (a *Authentication) MarshalBinary() ([]byte, error) { // 1 byte: Protocol // 1 byte: Algorithm // 1 byte: RDM // 8 bytes: ReplayDetection // N bytes: AuthenticationInformation (can have 0 len byte) b := buffer.New(nil) b.Write8(a.Protocol) b.Write8(a.Algorithm) b.Write8(a.RDM) b.Write64(a.ReplayDetection) b.WriteBytes(a.AuthenticationInformation) return b.Data(), nil }
go
func (a *Authentication) MarshalBinary() ([]byte, error) { // 1 byte: Protocol // 1 byte: Algorithm // 1 byte: RDM // 8 bytes: ReplayDetection // N bytes: AuthenticationInformation (can have 0 len byte) b := buffer.New(nil) b.Write8(a.Protocol) b.Write8(a.Algorithm) b.Write8(a.RDM) b.Write64(a.ReplayDetection) b.WriteBytes(a.AuthenticationInformation) return b.Data(), nil }
[ "func", "(", "a", "*", "Authentication", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// 1 byte: Protocol", "// 1 byte: Algorithm", "// 1 byte: RDM", "// 8 bytes: ReplayDetection", "// N bytes: AuthenticationInformation (can have 0 len byte)", "b", ":=", "buffer", ".", "New", "(", "nil", ")", "\n", "b", ".", "Write8", "(", "a", ".", "Protocol", ")", "\n", "b", ".", "Write8", "(", "a", ".", "Algorithm", ")", "\n", "b", ".", "Write8", "(", "a", ".", "RDM", ")", "\n", "b", ".", "Write64", "(", "a", ".", "ReplayDetection", ")", "\n", "b", ".", "WriteBytes", "(", "a", ".", "AuthenticationInformation", ")", "\n\n", "return", "b", ".", "Data", "(", ")", ",", "nil", "\n", "}" ]
// MarshalBinary allocates a byte slice containing the data from a Authentication.
[ "MarshalBinary", "allocates", "a", "byte", "slice", "containing", "the", "data", "from", "a", "Authentication", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/authentication.go#L31-L45
16,005
mdlayher/dhcp6
dhcp6opts/authentication.go
UnmarshalBinary
func (a *Authentication) UnmarshalBinary(p []byte) error { b := buffer.New(p) // Too short to be valid Authentication if b.Len() < 11 { return io.ErrUnexpectedEOF } a.Protocol = b.Read8() a.Algorithm = b.Read8() a.RDM = b.Read8() a.ReplayDetection = b.Read64() a.AuthenticationInformation = b.Remaining() return nil }
go
func (a *Authentication) UnmarshalBinary(p []byte) error { b := buffer.New(p) // Too short to be valid Authentication if b.Len() < 11 { return io.ErrUnexpectedEOF } a.Protocol = b.Read8() a.Algorithm = b.Read8() a.RDM = b.Read8() a.ReplayDetection = b.Read64() a.AuthenticationInformation = b.Remaining() return nil }
[ "func", "(", "a", "*", "Authentication", ")", "UnmarshalBinary", "(", "p", "[", "]", "byte", ")", "error", "{", "b", ":=", "buffer", ".", "New", "(", "p", ")", "\n", "// Too short to be valid Authentication", "if", "b", ".", "Len", "(", ")", "<", "11", "{", "return", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n\n", "a", ".", "Protocol", "=", "b", ".", "Read8", "(", ")", "\n", "a", ".", "Algorithm", "=", "b", ".", "Read8", "(", ")", "\n", "a", ".", "RDM", "=", "b", ".", "Read8", "(", ")", "\n", "a", ".", "ReplayDetection", "=", "b", ".", "Read64", "(", ")", "\n", "a", ".", "AuthenticationInformation", "=", "b", ".", "Remaining", "(", ")", "\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary unmarshals a raw byte slice into a Authentication. // If the byte slice does not contain enough data to form a valid // Authentication, io.ErrUnexpectedEOF is returned.
[ "UnmarshalBinary", "unmarshals", "a", "raw", "byte", "slice", "into", "a", "Authentication", ".", "If", "the", "byte", "slice", "does", "not", "contain", "enough", "data", "to", "form", "a", "valid", "Authentication", "io", ".", "ErrUnexpectedEOF", "is", "returned", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/authentication.go#L50-L63
16,006
mdlayher/dhcp6
dhcp6server/request.go
ParseRequest
func ParseRequest(b []byte, remoteAddr *net.UDPAddr) (*Request, error) { p := new(dhcp6.Packet) if err := p.UnmarshalBinary(b); err != nil { return nil, err } return &Request{ MessageType: p.MessageType, TransactionID: p.TransactionID, Options: p.Options, Length: int64(len(b)), RemoteAddr: remoteAddr.String(), }, nil }
go
func ParseRequest(b []byte, remoteAddr *net.UDPAddr) (*Request, error) { p := new(dhcp6.Packet) if err := p.UnmarshalBinary(b); err != nil { return nil, err } return &Request{ MessageType: p.MessageType, TransactionID: p.TransactionID, Options: p.Options, Length: int64(len(b)), RemoteAddr: remoteAddr.String(), }, nil }
[ "func", "ParseRequest", "(", "b", "[", "]", "byte", ",", "remoteAddr", "*", "net", ".", "UDPAddr", ")", "(", "*", "Request", ",", "error", ")", "{", "p", ":=", "new", "(", "dhcp6", ".", "Packet", ")", "\n", "if", "err", ":=", "p", ".", "UnmarshalBinary", "(", "b", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "Request", "{", "MessageType", ":", "p", ".", "MessageType", ",", "TransactionID", ":", "p", ".", "TransactionID", ",", "Options", ":", "p", ".", "Options", ",", "Length", ":", "int64", "(", "len", "(", "b", ")", ")", ",", "RemoteAddr", ":", "remoteAddr", ".", "String", "(", ")", ",", "}", ",", "nil", "\n", "}" ]
// ParseRequest creates a new Request from an input byte slice and UDP address. // It populates the basic struct members which can be used in a DHCP handler. // // If the input byte slice is not a valid DHCP packet, ErrInvalidPacket is // returned.
[ "ParseRequest", "creates", "a", "new", "Request", "from", "an", "input", "byte", "slice", "and", "UDP", "address", ".", "It", "populates", "the", "basic", "struct", "members", "which", "can", "be", "used", "in", "a", "DHCP", "handler", ".", "If", "the", "input", "byte", "slice", "is", "not", "a", "valid", "DHCP", "packet", "ErrInvalidPacket", "is", "returned", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6server/request.go#L40-L53
16,007
mdlayher/dhcp6
packet.go
MarshalBinary
func (p *Packet) MarshalBinary() ([]byte, error) { // 1 byte: message type // 3 bytes: transaction ID // N bytes: options slice byte count b := buffer.New(nil) b.Write8(uint8(p.MessageType)) b.WriteBytes(p.TransactionID[:]) opts, err := p.Options.MarshalBinary() if err != nil { return nil, err } b.WriteBytes(opts) return b.Data(), nil }
go
func (p *Packet) MarshalBinary() ([]byte, error) { // 1 byte: message type // 3 bytes: transaction ID // N bytes: options slice byte count b := buffer.New(nil) b.Write8(uint8(p.MessageType)) b.WriteBytes(p.TransactionID[:]) opts, err := p.Options.MarshalBinary() if err != nil { return nil, err } b.WriteBytes(opts) return b.Data(), nil }
[ "func", "(", "p", "*", "Packet", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// 1 byte: message type", "// 3 bytes: transaction ID", "// N bytes: options slice byte count", "b", ":=", "buffer", ".", "New", "(", "nil", ")", "\n\n", "b", ".", "Write8", "(", "uint8", "(", "p", ".", "MessageType", ")", ")", "\n", "b", ".", "WriteBytes", "(", "p", ".", "TransactionID", "[", ":", "]", ")", "\n\n", "opts", ",", "err", ":=", "p", ".", "Options", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "b", ".", "WriteBytes", "(", "opts", ")", "\n", "return", "b", ".", "Data", "(", ")", ",", "nil", "\n", "}" ]
// MarshalBinary allocates a byte slice containing the data // from a Packet.
[ "MarshalBinary", "allocates", "a", "byte", "slice", "containing", "the", "data", "from", "a", "Packet", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/packet.go#L29-L44
16,008
mdlayher/dhcp6
packet.go
UnmarshalBinary
func (p *Packet) UnmarshalBinary(q []byte) error { b := buffer.New(q) // Packet must contain at least a message type and transaction ID if b.Len() < 4 { return ErrInvalidPacket } p.MessageType = MessageType(b.Read8()) b.ReadBytes(p.TransactionID[:]) if err := (&p.Options).UnmarshalBinary(b.Remaining()); err != nil { return ErrInvalidPacket } return nil }
go
func (p *Packet) UnmarshalBinary(q []byte) error { b := buffer.New(q) // Packet must contain at least a message type and transaction ID if b.Len() < 4 { return ErrInvalidPacket } p.MessageType = MessageType(b.Read8()) b.ReadBytes(p.TransactionID[:]) if err := (&p.Options).UnmarshalBinary(b.Remaining()); err != nil { return ErrInvalidPacket } return nil }
[ "func", "(", "p", "*", "Packet", ")", "UnmarshalBinary", "(", "q", "[", "]", "byte", ")", "error", "{", "b", ":=", "buffer", ".", "New", "(", "q", ")", "\n", "// Packet must contain at least a message type and transaction ID", "if", "b", ".", "Len", "(", ")", "<", "4", "{", "return", "ErrInvalidPacket", "\n", "}", "\n\n", "p", ".", "MessageType", "=", "MessageType", "(", "b", ".", "Read8", "(", ")", ")", "\n", "b", ".", "ReadBytes", "(", "p", ".", "TransactionID", "[", ":", "]", ")", "\n\n", "if", "err", ":=", "(", "&", "p", ".", "Options", ")", ".", "UnmarshalBinary", "(", "b", ".", "Remaining", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "ErrInvalidPacket", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary unmarshals a raw byte slice into a Packet. // // If the byte slice does not contain enough data to form a valid Packet, // ErrInvalidPacket is returned.
[ "UnmarshalBinary", "unmarshals", "a", "raw", "byte", "slice", "into", "a", "Packet", ".", "If", "the", "byte", "slice", "does", "not", "contain", "enough", "data", "to", "form", "a", "valid", "Packet", "ErrInvalidPacket", "is", "returned", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/packet.go#L50-L64
16,009
mdlayher/dhcp6
dhcp6server/server.go
logf
func (s *Server) logf(format string, args ...interface{}) { if s.ErrorLog != nil { s.ErrorLog.Printf(format, args...) } else { log.Printf(format, args...) } }
go
func (s *Server) logf(format string, args ...interface{}) { if s.ErrorLog != nil { s.ErrorLog.Printf(format, args...) } else { log.Printf(format, args...) } }
[ "func", "(", "s", "*", "Server", ")", "logf", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "s", ".", "ErrorLog", "!=", "nil", "{", "s", ".", "ErrorLog", ".", "Printf", "(", "format", ",", "args", "...", ")", "\n", "}", "else", "{", "log", ".", "Printf", "(", "format", ",", "args", "...", ")", "\n", "}", "\n", "}" ]
// logf logs a message using the server's ErrorLog logger, or the log package // standard logger, if ErrorLog is nil.
[ "logf", "logs", "a", "message", "using", "the", "server", "s", "ErrorLog", "logger", "or", "the", "log", "package", "standard", "logger", "if", "ErrorLog", "is", "nil", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6server/server.go#L89-L95
16,010
mdlayher/dhcp6
dhcp6server/server.go
ListenAndServe
func ListenAndServe(iface string, handler Handler) error { // Verify network interface exists ifi, err := net.InterfaceByName(iface) if err != nil { return err } return (&Server{ Iface: ifi, Addr: "[::]:547", Handler: handler, MulticastGroups: []*net.IPAddr{ AllRelayAgentsAndServersAddr, AllServersAddr, }, }).ListenAndServe() }
go
func ListenAndServe(iface string, handler Handler) error { // Verify network interface exists ifi, err := net.InterfaceByName(iface) if err != nil { return err } return (&Server{ Iface: ifi, Addr: "[::]:547", Handler: handler, MulticastGroups: []*net.IPAddr{ AllRelayAgentsAndServersAddr, AllServersAddr, }, }).ListenAndServe() }
[ "func", "ListenAndServe", "(", "iface", "string", ",", "handler", "Handler", ")", "error", "{", "// Verify network interface exists", "ifi", ",", "err", ":=", "net", ".", "InterfaceByName", "(", "iface", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "(", "&", "Server", "{", "Iface", ":", "ifi", ",", "Addr", ":", "\"", "\"", ",", "Handler", ":", "handler", ",", "MulticastGroups", ":", "[", "]", "*", "net", ".", "IPAddr", "{", "AllRelayAgentsAndServersAddr", ",", "AllServersAddr", ",", "}", ",", "}", ")", ".", "ListenAndServe", "(", ")", "\n", "}" ]
// ListenAndServe listens for UDP6 connections on the specified address of the // specified interface, using the default Server configuration and specified // handler to handle DHCPv6 connections. The Handler must not be nil. // // Any traffic which reaches the Server, and is not bound for the specified // network interface, will be filtered out and ignored. // // In this configuration, the server acts as a DHCP server, but NOT as a // DHCP relay agent. For more information on DHCP relay agents, see RFC 3315, // Section 20.
[ "ListenAndServe", "listens", "for", "UDP6", "connections", "on", "the", "specified", "address", "of", "the", "specified", "interface", "using", "the", "default", "Server", "configuration", "and", "specified", "handler", "to", "handle", "DHCPv6", "connections", ".", "The", "Handler", "must", "not", "be", "nil", ".", "Any", "traffic", "which", "reaches", "the", "Server", "and", "is", "not", "bound", "for", "the", "specified", "network", "interface", "will", "be", "filtered", "out", "and", "ignored", ".", "In", "this", "configuration", "the", "server", "acts", "as", "a", "DHCP", "server", "but", "NOT", "as", "a", "DHCP", "relay", "agent", ".", "For", "more", "information", "on", "DHCP", "relay", "agents", "see", "RFC", "3315", "Section", "20", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6server/server.go#L107-L123
16,011
mdlayher/dhcp6
dhcp6server/server.go
ListenAndServe
func (s *Server) ListenAndServe() error { // Open UDP6 packet connection listener on specified address conn, err := net.ListenPacket("udp6", s.Addr) if err != nil { return err } defer conn.Close() return s.Serve(ipv6.NewPacketConn(conn)) }
go
func (s *Server) ListenAndServe() error { // Open UDP6 packet connection listener on specified address conn, err := net.ListenPacket("udp6", s.Addr) if err != nil { return err } defer conn.Close() return s.Serve(ipv6.NewPacketConn(conn)) }
[ "func", "(", "s", "*", "Server", ")", "ListenAndServe", "(", ")", "error", "{", "// Open UDP6 packet connection listener on specified address", "conn", ",", "err", ":=", "net", ".", "ListenPacket", "(", "\"", "\"", ",", "s", ".", "Addr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "defer", "conn", ".", "Close", "(", ")", "\n", "return", "s", ".", "Serve", "(", "ipv6", ".", "NewPacketConn", "(", "conn", ")", ")", "\n", "}" ]
// ListenAndServe listens on the address specified by s.Addr using the network // interface defined in s.Iface. Traffic from any other interface will be // filtered out and ignored. Serve is called to handle serving DHCP traffic // once ListenAndServe opens a UDP6 packet connection.
[ "ListenAndServe", "listens", "on", "the", "address", "specified", "by", "s", ".", "Addr", "using", "the", "network", "interface", "defined", "in", "s", ".", "Iface", ".", "Traffic", "from", "any", "other", "interface", "will", "be", "filtered", "out", "and", "ignored", ".", "Serve", "is", "called", "to", "handle", "serving", "DHCP", "traffic", "once", "ListenAndServe", "opens", "a", "UDP6", "packet", "connection", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6server/server.go#L129-L138
16,012
mdlayher/dhcp6
dhcp6server/server.go
Serve
func (s *Server) Serve(p PacketConn) error { // If no DUID was set for server previously, generate a DUID-LL // now using the interface's hardware address, and just assume the // "Ethernet 10Mb" hardware type since the caller probably doesn't care. if s.ServerID == nil { const ethernet10Mb uint16 = 1 s.ServerID = dhcp6opts.NewDUIDLL(ethernet10Mb, s.Iface.HardwareAddr) } // Filter any traffic which does not indicate the interface // defined by s.Iface. if err := p.SetControlMessage(ipv6.FlagInterface, true); err != nil { return err } // Join appropriate multicast groups for _, g := range s.MulticastGroups { if err := p.JoinGroup(s.Iface, g); err != nil { return err } } // Set up IPv6 packet connection, and on return, handle leaving multicast // groups and closing connection defer func() { for _, g := range s.MulticastGroups { _ = p.LeaveGroup(s.Iface, g) } _ = p.Close() }() // Loop and read requests until exit buf := make([]byte, 1500) for { n, cm, addr, err := p.ReadFrom(buf) if err != nil { // Stop serve loop gracefully when closing if err == errClosing { return nil } // BUG(mdlayher): determine if error can be temporary return err } // Filter any traffic with a control message indicating an incorrect // interface index if cm != nil && cm.IfIndex != s.Iface.Index { continue } // Create conn struct with data specific to this connection uc, err := s.newConn(p, addr.(*net.UDPAddr), n, buf) if err != nil { continue } // Serve conn and continue looping for more connections go uc.serve() } }
go
func (s *Server) Serve(p PacketConn) error { // If no DUID was set for server previously, generate a DUID-LL // now using the interface's hardware address, and just assume the // "Ethernet 10Mb" hardware type since the caller probably doesn't care. if s.ServerID == nil { const ethernet10Mb uint16 = 1 s.ServerID = dhcp6opts.NewDUIDLL(ethernet10Mb, s.Iface.HardwareAddr) } // Filter any traffic which does not indicate the interface // defined by s.Iface. if err := p.SetControlMessage(ipv6.FlagInterface, true); err != nil { return err } // Join appropriate multicast groups for _, g := range s.MulticastGroups { if err := p.JoinGroup(s.Iface, g); err != nil { return err } } // Set up IPv6 packet connection, and on return, handle leaving multicast // groups and closing connection defer func() { for _, g := range s.MulticastGroups { _ = p.LeaveGroup(s.Iface, g) } _ = p.Close() }() // Loop and read requests until exit buf := make([]byte, 1500) for { n, cm, addr, err := p.ReadFrom(buf) if err != nil { // Stop serve loop gracefully when closing if err == errClosing { return nil } // BUG(mdlayher): determine if error can be temporary return err } // Filter any traffic with a control message indicating an incorrect // interface index if cm != nil && cm.IfIndex != s.Iface.Index { continue } // Create conn struct with data specific to this connection uc, err := s.newConn(p, addr.(*net.UDPAddr), n, buf) if err != nil { continue } // Serve conn and continue looping for more connections go uc.serve() } }
[ "func", "(", "s", "*", "Server", ")", "Serve", "(", "p", "PacketConn", ")", "error", "{", "// If no DUID was set for server previously, generate a DUID-LL", "// now using the interface's hardware address, and just assume the", "// \"Ethernet 10Mb\" hardware type since the caller probably doesn't care.", "if", "s", ".", "ServerID", "==", "nil", "{", "const", "ethernet10Mb", "uint16", "=", "1", "\n", "s", ".", "ServerID", "=", "dhcp6opts", ".", "NewDUIDLL", "(", "ethernet10Mb", ",", "s", ".", "Iface", ".", "HardwareAddr", ")", "\n", "}", "\n\n", "// Filter any traffic which does not indicate the interface", "// defined by s.Iface.", "if", "err", ":=", "p", ".", "SetControlMessage", "(", "ipv6", ".", "FlagInterface", ",", "true", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Join appropriate multicast groups", "for", "_", ",", "g", ":=", "range", "s", ".", "MulticastGroups", "{", "if", "err", ":=", "p", ".", "JoinGroup", "(", "s", ".", "Iface", ",", "g", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Set up IPv6 packet connection, and on return, handle leaving multicast", "// groups and closing connection", "defer", "func", "(", ")", "{", "for", "_", ",", "g", ":=", "range", "s", ".", "MulticastGroups", "{", "_", "=", "p", ".", "LeaveGroup", "(", "s", ".", "Iface", ",", "g", ")", "\n", "}", "\n\n", "_", "=", "p", ".", "Close", "(", ")", "\n", "}", "(", ")", "\n\n", "// Loop and read requests until exit", "buf", ":=", "make", "(", "[", "]", "byte", ",", "1500", ")", "\n", "for", "{", "n", ",", "cm", ",", "addr", ",", "err", ":=", "p", ".", "ReadFrom", "(", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "// Stop serve loop gracefully when closing", "if", "err", "==", "errClosing", "{", "return", "nil", "\n", "}", "\n\n", "// BUG(mdlayher): determine if error can be temporary", "return", "err", "\n", "}", "\n\n", "// Filter any traffic with a control message indicating an incorrect", "// interface index", "if", "cm", "!=", "nil", "&&", "cm", ".", "IfIndex", "!=", "s", ".", "Iface", ".", "Index", "{", "continue", "\n", "}", "\n\n", "// Create conn struct with data specific to this connection", "uc", ",", "err", ":=", "s", ".", "newConn", "(", "p", ",", "addr", ".", "(", "*", "net", ".", "UDPAddr", ")", ",", "n", ",", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "continue", "\n", "}", "\n\n", "// Serve conn and continue looping for more connections", "go", "uc", ".", "serve", "(", ")", "\n", "}", "\n", "}" ]
// Serve configures and accepts incoming connections on PacketConn p, creating a // new goroutine for each. Serve configures IPv6 control message settings, joins // the appropriate multicast groups, and begins listening for incoming connections. // // The service goroutine reads requests, generate the appropriate Request and // ResponseSender values, then calls s.Handler to handle the request.
[ "Serve", "configures", "and", "accepts", "incoming", "connections", "on", "PacketConn", "p", "creating", "a", "new", "goroutine", "for", "each", ".", "Serve", "configures", "IPv6", "control", "message", "settings", "joins", "the", "appropriate", "multicast", "groups", "and", "begins", "listening", "for", "incoming", "connections", ".", "The", "service", "goroutine", "reads", "requests", "generate", "the", "appropriate", "Request", "and", "ResponseSender", "values", "then", "calls", "s", ".", "Handler", "to", "handle", "the", "request", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6server/server.go#L146-L207
16,013
mdlayher/dhcp6
dhcp6server/server.go
Send
func (r *response) Send(mt dhcp6.MessageType) (int, error) { p := &dhcp6.Packet{ MessageType: mt, TransactionID: r.req.TransactionID, Options: r.options, } b, err := p.MarshalBinary() if err != nil { return 0, err } return r.conn.WriteTo(b, nil, r.remoteAddr) }
go
func (r *response) Send(mt dhcp6.MessageType) (int, error) { p := &dhcp6.Packet{ MessageType: mt, TransactionID: r.req.TransactionID, Options: r.options, } b, err := p.MarshalBinary() if err != nil { return 0, err } return r.conn.WriteTo(b, nil, r.remoteAddr) }
[ "func", "(", "r", "*", "response", ")", "Send", "(", "mt", "dhcp6", ".", "MessageType", ")", "(", "int", ",", "error", ")", "{", "p", ":=", "&", "dhcp6", ".", "Packet", "{", "MessageType", ":", "mt", ",", "TransactionID", ":", "r", ".", "req", ".", "TransactionID", ",", "Options", ":", "r", ".", "options", ",", "}", "\n\n", "b", ",", "err", ":=", "p", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "return", "r", ".", "conn", ".", "WriteTo", "(", "b", ",", "nil", ",", "r", ".", "remoteAddr", ")", "\n", "}" ]
// Send uses the input message typ, the transaction ID sent by a client, // and the options set by Options, to create and send a Packet to the // client's address.
[ "Send", "uses", "the", "input", "message", "typ", "the", "transaction", "ID", "sent", "by", "a", "client", "and", "the", "options", "set", "by", "Options", "to", "create", "and", "send", "a", "Packet", "to", "the", "client", "s", "address", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6server/server.go#L255-L268
16,014
mdlayher/dhcp6
dhcp6server/server.go
serve
func (c *conn) serve() { // Attempt to parse a Request from a raw packet, providing a nicer // API for callers to implement their own DHCP request handlers. r, err := ParseRequest(c.buf, c.remoteAddr) if err != nil { // Malformed packets get no response if err == dhcp6.ErrInvalidPacket { return } // BUG(mdlayher): decide to log or handle other request errors c.server.logf("%s: error parsing request: %s", c.remoteAddr.String(), err.Error()) return } // Filter out unknown/invalid message types, using the lowest and highest // numbered types if r.MessageType < dhcp6.MessageTypeSolicit || r.MessageType > dhcp6.MessageTypeDHCPv4Response { c.server.logf("%s: unrecognized message type: %d", c.remoteAddr.String(), r.MessageType) return } // Set up response to send responses back to the original requester w := &response{ remoteAddr: c.remoteAddr, conn: c.conn, req: r, options: make(dhcp6.Options), } // Add server ID to response if sID := c.server.ServerID; sID != nil { _ = w.options.Add(dhcp6.OptionServerID, sID) } // If available in request, add client ID to response if cID, err := dhcp6opts.GetClientID(r.Options); err == nil { w.options.Add(dhcp6.OptionClientID, cID) } // Enforce a valid Handler. handler := c.server.Handler if handler == nil { panic("nil DHCPv6 handler for server") } handler.ServeDHCP(w, r) }
go
func (c *conn) serve() { // Attempt to parse a Request from a raw packet, providing a nicer // API for callers to implement their own DHCP request handlers. r, err := ParseRequest(c.buf, c.remoteAddr) if err != nil { // Malformed packets get no response if err == dhcp6.ErrInvalidPacket { return } // BUG(mdlayher): decide to log or handle other request errors c.server.logf("%s: error parsing request: %s", c.remoteAddr.String(), err.Error()) return } // Filter out unknown/invalid message types, using the lowest and highest // numbered types if r.MessageType < dhcp6.MessageTypeSolicit || r.MessageType > dhcp6.MessageTypeDHCPv4Response { c.server.logf("%s: unrecognized message type: %d", c.remoteAddr.String(), r.MessageType) return } // Set up response to send responses back to the original requester w := &response{ remoteAddr: c.remoteAddr, conn: c.conn, req: r, options: make(dhcp6.Options), } // Add server ID to response if sID := c.server.ServerID; sID != nil { _ = w.options.Add(dhcp6.OptionServerID, sID) } // If available in request, add client ID to response if cID, err := dhcp6opts.GetClientID(r.Options); err == nil { w.options.Add(dhcp6.OptionClientID, cID) } // Enforce a valid Handler. handler := c.server.Handler if handler == nil { panic("nil DHCPv6 handler for server") } handler.ServeDHCP(w, r) }
[ "func", "(", "c", "*", "conn", ")", "serve", "(", ")", "{", "// Attempt to parse a Request from a raw packet, providing a nicer", "// API for callers to implement their own DHCP request handlers.", "r", ",", "err", ":=", "ParseRequest", "(", "c", ".", "buf", ",", "c", ".", "remoteAddr", ")", "\n", "if", "err", "!=", "nil", "{", "// Malformed packets get no response", "if", "err", "==", "dhcp6", ".", "ErrInvalidPacket", "{", "return", "\n", "}", "\n\n", "// BUG(mdlayher): decide to log or handle other request errors", "c", ".", "server", ".", "logf", "(", "\"", "\"", ",", "c", ".", "remoteAddr", ".", "String", "(", ")", ",", "err", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n\n", "// Filter out unknown/invalid message types, using the lowest and highest", "// numbered types", "if", "r", ".", "MessageType", "<", "dhcp6", ".", "MessageTypeSolicit", "||", "r", ".", "MessageType", ">", "dhcp6", ".", "MessageTypeDHCPv4Response", "{", "c", ".", "server", ".", "logf", "(", "\"", "\"", ",", "c", ".", "remoteAddr", ".", "String", "(", ")", ",", "r", ".", "MessageType", ")", "\n", "return", "\n", "}", "\n\n", "// Set up response to send responses back to the original requester", "w", ":=", "&", "response", "{", "remoteAddr", ":", "c", ".", "remoteAddr", ",", "conn", ":", "c", ".", "conn", ",", "req", ":", "r", ",", "options", ":", "make", "(", "dhcp6", ".", "Options", ")", ",", "}", "\n\n", "// Add server ID to response", "if", "sID", ":=", "c", ".", "server", ".", "ServerID", ";", "sID", "!=", "nil", "{", "_", "=", "w", ".", "options", ".", "Add", "(", "dhcp6", ".", "OptionServerID", ",", "sID", ")", "\n", "}", "\n\n", "// If available in request, add client ID to response", "if", "cID", ",", "err", ":=", "dhcp6opts", ".", "GetClientID", "(", "r", ".", "Options", ")", ";", "err", "==", "nil", "{", "w", ".", "options", ".", "Add", "(", "dhcp6", ".", "OptionClientID", ",", "cID", ")", "\n", "}", "\n\n", "// Enforce a valid Handler.", "handler", ":=", "c", ".", "server", ".", "Handler", "\n", "if", "handler", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "handler", ".", "ServeDHCP", "(", "w", ",", "r", ")", "\n", "}" ]
// serve handles serving an individual DHCP connection, and is invoked in a // goroutine.
[ "serve", "handles", "serving", "an", "individual", "DHCP", "connection", "and", "is", "invoked", "in", "a", "goroutine", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6server/server.go#L272-L319
16,015
mdlayher/dhcp6
dhcp6opts/remoteid.go
MarshalBinary
func (r *RemoteIdentifier) MarshalBinary() ([]byte, error) { // 4 bytes: EnterpriseNumber // N bytes: RemoteId b := buffer.New(nil) b.Write32(r.EnterpriseNumber) b.WriteBytes(r.RemoteID) return b.Data(), nil }
go
func (r *RemoteIdentifier) MarshalBinary() ([]byte, error) { // 4 bytes: EnterpriseNumber // N bytes: RemoteId b := buffer.New(nil) b.Write32(r.EnterpriseNumber) b.WriteBytes(r.RemoteID) return b.Data(), nil }
[ "func", "(", "r", "*", "RemoteIdentifier", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// 4 bytes: EnterpriseNumber", "// N bytes: RemoteId", "b", ":=", "buffer", ".", "New", "(", "nil", ")", "\n", "b", ".", "Write32", "(", "r", ".", "EnterpriseNumber", ")", "\n", "b", ".", "WriteBytes", "(", "r", ".", "RemoteID", ")", "\n", "return", "b", ".", "Data", "(", ")", ",", "nil", "\n", "}" ]
// MarshalBinary allocates a byte slice containing the data // from a RemoteIdentifier.
[ "MarshalBinary", "allocates", "a", "byte", "slice", "containing", "the", "data", "from", "a", "RemoteIdentifier", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/remoteid.go#L31-L38
16,016
mdlayher/dhcp6
dhcp6opts/remoteid.go
UnmarshalBinary
func (r *RemoteIdentifier) UnmarshalBinary(p []byte) error { b := buffer.New(p) // Too short to be valid RemoteIdentifier if b.Len() < 5 { return io.ErrUnexpectedEOF } r.EnterpriseNumber = b.Read32() r.RemoteID = b.Remaining() return nil }
go
func (r *RemoteIdentifier) UnmarshalBinary(p []byte) error { b := buffer.New(p) // Too short to be valid RemoteIdentifier if b.Len() < 5 { return io.ErrUnexpectedEOF } r.EnterpriseNumber = b.Read32() r.RemoteID = b.Remaining() return nil }
[ "func", "(", "r", "*", "RemoteIdentifier", ")", "UnmarshalBinary", "(", "p", "[", "]", "byte", ")", "error", "{", "b", ":=", "buffer", ".", "New", "(", "p", ")", "\n", "// Too short to be valid RemoteIdentifier", "if", "b", ".", "Len", "(", ")", "<", "5", "{", "return", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n\n", "r", ".", "EnterpriseNumber", "=", "b", ".", "Read32", "(", ")", "\n", "r", ".", "RemoteID", "=", "b", ".", "Remaining", "(", ")", "\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary unmarshals a raw byte slice into a RemoteIdentifier. // If the byte slice does not contain enough data to form a valid // RemoteIdentifier, io.ErrUnexpectedEOF is returned.
[ "UnmarshalBinary", "unmarshals", "a", "raw", "byte", "slice", "into", "a", "RemoteIdentifier", ".", "If", "the", "byte", "slice", "does", "not", "contain", "enough", "data", "to", "form", "a", "valid", "RemoteIdentifier", "io", ".", "ErrUnexpectedEOF", "is", "returned", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/remoteid.go#L43-L53
16,017
mdlayher/dhcp6
internal/buffer/buffer.go
append
func (b *Buffer) append(n int) []byte { b.data = append(b.data, make([]byte, n)...) return b.data[len(b.data)-n:] }
go
func (b *Buffer) append(n int) []byte { b.data = append(b.data, make([]byte, n)...) return b.data[len(b.data)-n:] }
[ "func", "(", "b", "*", "Buffer", ")", "append", "(", "n", "int", ")", "[", "]", "byte", "{", "b", ".", "data", "=", "append", "(", "b", ".", "data", ",", "make", "(", "[", "]", "byte", ",", "n", ")", "...", ")", "\n", "return", "b", ".", "data", "[", "len", "(", "b", ".", "data", ")", "-", "n", ":", "]", "\n", "}" ]
// append appends n bytes to the Buffer and returns a slice pointing to the // newly appended bytes.
[ "append", "appends", "n", "bytes", "to", "the", "Buffer", "and", "returns", "a", "slice", "pointing", "to", "the", "newly", "appended", "bytes", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/internal/buffer/buffer.go#L22-L25
16,018
mdlayher/dhcp6
internal/buffer/buffer.go
Remaining
func (b *Buffer) Remaining() []byte { p := b.Consume(len(b.Data())) cp := make([]byte, len(p)) copy(cp, p) return cp }
go
func (b *Buffer) Remaining() []byte { p := b.Consume(len(b.Data())) cp := make([]byte, len(p)) copy(cp, p) return cp }
[ "func", "(", "b", "*", "Buffer", ")", "Remaining", "(", ")", "[", "]", "byte", "{", "p", ":=", "b", ".", "Consume", "(", "len", "(", "b", ".", "Data", "(", ")", ")", ")", "\n", "cp", ":=", "make", "(", "[", "]", "byte", ",", "len", "(", "p", ")", ")", "\n", "copy", "(", "cp", ",", "p", ")", "\n", "return", "cp", "\n", "}" ]
// Remaining consumes and returns a copy of all remaining bytes in the Buffer.
[ "Remaining", "consumes", "and", "returns", "a", "copy", "of", "all", "remaining", "bytes", "in", "the", "Buffer", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/internal/buffer/buffer.go#L33-L38
16,019
mdlayher/dhcp6
internal/buffer/buffer.go
consume
func (b *Buffer) consume(n int) ([]byte, bool) { if !b.Has(n) { return nil, false } rval := b.data[:n] b.data = b.data[n:] return rval, true }
go
func (b *Buffer) consume(n int) ([]byte, bool) { if !b.Has(n) { return nil, false } rval := b.data[:n] b.data = b.data[n:] return rval, true }
[ "func", "(", "b", "*", "Buffer", ")", "consume", "(", "n", "int", ")", "(", "[", "]", "byte", ",", "bool", ")", "{", "if", "!", "b", ".", "Has", "(", "n", ")", "{", "return", "nil", ",", "false", "\n", "}", "\n", "rval", ":=", "b", ".", "data", "[", ":", "n", "]", "\n", "b", ".", "data", "=", "b", ".", "data", "[", "n", ":", "]", "\n", "return", "rval", ",", "true", "\n", "}" ]
// consume consumes n bytes from the Buffer. It returns nil, false if there // aren't enough bytes left.
[ "consume", "consumes", "n", "bytes", "from", "the", "Buffer", ".", "It", "returns", "nil", "false", "if", "there", "aren", "t", "enough", "bytes", "left", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/internal/buffer/buffer.go#L42-L49
16,020
mdlayher/dhcp6
internal/buffer/buffer.go
Consume
func (b *Buffer) Consume(n int) []byte { v, ok := b.consume(n) if !ok { return nil } return v }
go
func (b *Buffer) Consume(n int) []byte { v, ok := b.consume(n) if !ok { return nil } return v }
[ "func", "(", "b", "*", "Buffer", ")", "Consume", "(", "n", "int", ")", "[", "]", "byte", "{", "v", ",", "ok", ":=", "b", ".", "consume", "(", "n", ")", "\n", "if", "!", "ok", "{", "return", "nil", "\n", "}", "\n", "return", "v", "\n", "}" ]
// Consume consumes n bytes from the Buffer. It returns nil if there aren't // enough bytes left.
[ "Consume", "consumes", "n", "bytes", "from", "the", "Buffer", ".", "It", "returns", "nil", "if", "there", "aren", "t", "enough", "bytes", "left", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/internal/buffer/buffer.go#L53-L59
16,021
mdlayher/dhcp6
internal/buffer/buffer.go
Has
func (b *Buffer) Has(n int) bool { return len(b.data) >= n }
go
func (b *Buffer) Has(n int) bool { return len(b.data) >= n }
[ "func", "(", "b", "*", "Buffer", ")", "Has", "(", "n", "int", ")", "bool", "{", "return", "len", "(", "b", ".", "data", ")", ">=", "n", "\n", "}" ]
// Has returns true if n bytes are available.
[ "Has", "returns", "true", "if", "n", "bytes", "are", "available", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/internal/buffer/buffer.go#L62-L64
16,022
mdlayher/dhcp6
internal/buffer/buffer.go
Read8
func (b *Buffer) Read8() uint8 { v, ok := b.consume(1) if !ok { return 0 } return uint8(v[0]) }
go
func (b *Buffer) Read8() uint8 { v, ok := b.consume(1) if !ok { return 0 } return uint8(v[0]) }
[ "func", "(", "b", "*", "Buffer", ")", "Read8", "(", ")", "uint8", "{", "v", ",", "ok", ":=", "b", ".", "consume", "(", "1", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "uint8", "(", "v", "[", "0", "]", ")", "\n", "}" ]
// Read8 reads a byte from the Buffer.
[ "Read8", "reads", "a", "byte", "from", "the", "Buffer", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/internal/buffer/buffer.go#L72-L78
16,023
mdlayher/dhcp6
internal/buffer/buffer.go
Read16
func (b *Buffer) Read16() uint16 { v, ok := b.consume(2) if !ok { return 0 } return order.Uint16(v) }
go
func (b *Buffer) Read16() uint16 { v, ok := b.consume(2) if !ok { return 0 } return order.Uint16(v) }
[ "func", "(", "b", "*", "Buffer", ")", "Read16", "(", ")", "uint16", "{", "v", ",", "ok", ":=", "b", ".", "consume", "(", "2", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "order", ".", "Uint16", "(", "v", ")", "\n", "}" ]
// Read16 reads a 16-bit value from the Buffer.
[ "Read16", "reads", "a", "16", "-", "bit", "value", "from", "the", "Buffer", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/internal/buffer/buffer.go#L81-L87
16,024
mdlayher/dhcp6
internal/buffer/buffer.go
Read32
func (b *Buffer) Read32() uint32 { v, ok := b.consume(4) if !ok { return 0 } return order.Uint32(v) }
go
func (b *Buffer) Read32() uint32 { v, ok := b.consume(4) if !ok { return 0 } return order.Uint32(v) }
[ "func", "(", "b", "*", "Buffer", ")", "Read32", "(", ")", "uint32", "{", "v", ",", "ok", ":=", "b", ".", "consume", "(", "4", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "order", ".", "Uint32", "(", "v", ")", "\n", "}" ]
// Read32 reads a 32-bit value from the Buffer.
[ "Read32", "reads", "a", "32", "-", "bit", "value", "from", "the", "Buffer", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/internal/buffer/buffer.go#L90-L96
16,025
mdlayher/dhcp6
internal/buffer/buffer.go
Read64
func (b *Buffer) Read64() uint64 { v, ok := b.consume(8) if !ok { return 0 } return order.Uint64(v) }
go
func (b *Buffer) Read64() uint64 { v, ok := b.consume(8) if !ok { return 0 } return order.Uint64(v) }
[ "func", "(", "b", "*", "Buffer", ")", "Read64", "(", ")", "uint64", "{", "v", ",", "ok", ":=", "b", ".", "consume", "(", "8", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "order", ".", "Uint64", "(", "v", ")", "\n", "}" ]
// Read64 reads a 64-bit value from the Buffer.
[ "Read64", "reads", "a", "64", "-", "bit", "value", "from", "the", "Buffer", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/internal/buffer/buffer.go#L99-L105
16,026
mdlayher/dhcp6
internal/buffer/buffer.go
Write16
func (b *Buffer) Write16(v uint16) { order.PutUint16(b.append(2), v) }
go
func (b *Buffer) Write16(v uint16) { order.PutUint16(b.append(2), v) }
[ "func", "(", "b", "*", "Buffer", ")", "Write16", "(", "v", "uint16", ")", "{", "order", ".", "PutUint16", "(", "b", ".", "append", "(", "2", ")", ",", "v", ")", "\n", "}" ]
// Write16 writes a 16-bit value to the Buffer.
[ "Write16", "writes", "a", "16", "-", "bit", "value", "to", "the", "Buffer", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/internal/buffer/buffer.go#L118-L120
16,027
mdlayher/dhcp6
internal/buffer/buffer.go
Write32
func (b *Buffer) Write32(v uint32) { order.PutUint32(b.append(4), v) }
go
func (b *Buffer) Write32(v uint32) { order.PutUint32(b.append(4), v) }
[ "func", "(", "b", "*", "Buffer", ")", "Write32", "(", "v", "uint32", ")", "{", "order", ".", "PutUint32", "(", "b", ".", "append", "(", "4", ")", ",", "v", ")", "\n", "}" ]
// Write32 writes a 32-bit value to the Buffer.
[ "Write32", "writes", "a", "32", "-", "bit", "value", "to", "the", "Buffer", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/internal/buffer/buffer.go#L123-L125
16,028
mdlayher/dhcp6
internal/buffer/buffer.go
Write64
func (b *Buffer) Write64(v uint64) { order.PutUint64(b.append(8), v) }
go
func (b *Buffer) Write64(v uint64) { order.PutUint64(b.append(8), v) }
[ "func", "(", "b", "*", "Buffer", ")", "Write64", "(", "v", "uint64", ")", "{", "order", ".", "PutUint64", "(", "b", ".", "append", "(", "8", ")", ",", "v", ")", "\n", "}" ]
// Write64 writes a 64-bit value to the Buffer.
[ "Write64", "writes", "a", "64", "-", "bit", "value", "to", "the", "Buffer", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/internal/buffer/buffer.go#L128-L130
16,029
mdlayher/dhcp6
internal/buffer/buffer.go
WriteBytes
func (b *Buffer) WriteBytes(p []byte) { copy(b.append(len(p)), p) }
go
func (b *Buffer) WriteBytes(p []byte) { copy(b.append(len(p)), p) }
[ "func", "(", "b", "*", "Buffer", ")", "WriteBytes", "(", "p", "[", "]", "byte", ")", "{", "copy", "(", "b", ".", "append", "(", "len", "(", "p", ")", ")", ",", "p", ")", "\n", "}" ]
// WriteBytes writes p to the Buffer.
[ "WriteBytes", "writes", "p", "to", "the", "Buffer", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/internal/buffer/buffer.go#L138-L140
16,030
mdlayher/dhcp6
dhcp6opts/iana.go
NewIANA
func NewIANA(iaid [4]byte, t1 time.Duration, t2 time.Duration, options dhcp6.Options) *IANA { if options == nil { options = make(dhcp6.Options) } return &IANA{ IAID: iaid, T1: t1, T2: t2, Options: options, } }
go
func NewIANA(iaid [4]byte, t1 time.Duration, t2 time.Duration, options dhcp6.Options) *IANA { if options == nil { options = make(dhcp6.Options) } return &IANA{ IAID: iaid, T1: t1, T2: t2, Options: options, } }
[ "func", "NewIANA", "(", "iaid", "[", "4", "]", "byte", ",", "t1", "time", ".", "Duration", ",", "t2", "time", ".", "Duration", ",", "options", "dhcp6", ".", "Options", ")", "*", "IANA", "{", "if", "options", "==", "nil", "{", "options", "=", "make", "(", "dhcp6", ".", "Options", ")", "\n", "}", "\n\n", "return", "&", "IANA", "{", "IAID", ":", "iaid", ",", "T1", ":", "t1", ",", "T2", ":", "t2", ",", "Options", ":", "options", ",", "}", "\n", "}" ]
// NewIANA creates a new IANA from an IAID, T1 and T2 durations, and an // Options map. If an Options map is not specified, a new one will be // allocated.
[ "NewIANA", "creates", "a", "new", "IANA", "from", "an", "IAID", "T1", "and", "T2", "durations", "and", "an", "Options", "map", ".", "If", "an", "Options", "map", "is", "not", "specified", "a", "new", "one", "will", "be", "allocated", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/iana.go#L39-L50
16,031
mdlayher/dhcp6
dhcp6opts/iana.go
UnmarshalBinary
func (i *IANA) UnmarshalBinary(p []byte) error { // IANA must contain at least an IAID, T1, and T2. b := buffer.New(p) if b.Len() < 12 { return io.ErrUnexpectedEOF } b.ReadBytes(i.IAID[:]) i.T1 = time.Duration(b.Read32()) * time.Second i.T2 = time.Duration(b.Read32()) * time.Second return (&i.Options).UnmarshalBinary(b.Remaining()) }
go
func (i *IANA) UnmarshalBinary(p []byte) error { // IANA must contain at least an IAID, T1, and T2. b := buffer.New(p) if b.Len() < 12 { return io.ErrUnexpectedEOF } b.ReadBytes(i.IAID[:]) i.T1 = time.Duration(b.Read32()) * time.Second i.T2 = time.Duration(b.Read32()) * time.Second return (&i.Options).UnmarshalBinary(b.Remaining()) }
[ "func", "(", "i", "*", "IANA", ")", "UnmarshalBinary", "(", "p", "[", "]", "byte", ")", "error", "{", "// IANA must contain at least an IAID, T1, and T2.", "b", ":=", "buffer", ".", "New", "(", "p", ")", "\n", "if", "b", ".", "Len", "(", ")", "<", "12", "{", "return", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n\n", "b", ".", "ReadBytes", "(", "i", ".", "IAID", "[", ":", "]", ")", "\n", "i", ".", "T1", "=", "time", ".", "Duration", "(", "b", ".", "Read32", "(", ")", ")", "*", "time", ".", "Second", "\n", "i", ".", "T2", "=", "time", ".", "Duration", "(", "b", ".", "Read32", "(", ")", ")", "*", "time", ".", "Second", "\n\n", "return", "(", "&", "i", ".", "Options", ")", ".", "UnmarshalBinary", "(", "b", ".", "Remaining", "(", ")", ")", "\n", "}" ]
// UnmarshalBinary unmarshals a raw byte slice into a IANA. // // If the byte slice does not contain enough data to form a valid IANA, // io.ErrUnexpectedEOF is returned.
[ "UnmarshalBinary", "unmarshals", "a", "raw", "byte", "slice", "into", "a", "IANA", ".", "If", "the", "byte", "slice", "does", "not", "contain", "enough", "data", "to", "form", "a", "valid", "IANA", "io", ".", "ErrUnexpectedEOF", "is", "returned", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/iana.go#L76-L88
16,032
mdlayher/dhcp6
dhcp6opts/duid.go
MarshalBinary
func (d *DUIDLLT) MarshalBinary() ([]byte, error) { // 2 bytes: DUID type // 2 bytes: hardware type // 4 bytes: time duration // N bytes: hardware address b := buffer.New(nil) b.Write16(uint16(d.Type)) b.Write16(d.HardwareType) b.Write32(uint32(d.Time / time.Second)) b.WriteBytes(d.HardwareAddr) return b.Data(), nil }
go
func (d *DUIDLLT) MarshalBinary() ([]byte, error) { // 2 bytes: DUID type // 2 bytes: hardware type // 4 bytes: time duration // N bytes: hardware address b := buffer.New(nil) b.Write16(uint16(d.Type)) b.Write16(d.HardwareType) b.Write32(uint32(d.Time / time.Second)) b.WriteBytes(d.HardwareAddr) return b.Data(), nil }
[ "func", "(", "d", "*", "DUIDLLT", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// 2 bytes: DUID type", "// 2 bytes: hardware type", "// 4 bytes: time duration", "// N bytes: hardware address", "b", ":=", "buffer", ".", "New", "(", "nil", ")", "\n\n", "b", ".", "Write16", "(", "uint16", "(", "d", ".", "Type", ")", ")", "\n", "b", ".", "Write16", "(", "d", ".", "HardwareType", ")", "\n", "b", ".", "Write32", "(", "uint32", "(", "d", ".", "Time", "/", "time", ".", "Second", ")", ")", "\n", "b", ".", "WriteBytes", "(", "d", ".", "HardwareAddr", ")", "\n\n", "return", "b", ".", "Data", "(", ")", ",", "nil", "\n", "}" ]
// MarshalBinary allocates a byte slice containing the data from a DUIDLLT.
[ "MarshalBinary", "allocates", "a", "byte", "slice", "containing", "the", "data", "from", "a", "DUIDLLT", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/duid.go#L141-L154
16,033
mdlayher/dhcp6
dhcp6opts/duid.go
UnmarshalBinary
func (d *DUIDLLT) UnmarshalBinary(p []byte) error { b := buffer.New(p) // Too short to be valid DUIDLLT if b.Len() < 8 { return io.ErrUnexpectedEOF } // Verify DUID type dType := DUIDType(b.Read16()) if dType != DUIDTypeLLT { return errInvalidDUIDLLT } d.Type = dType d.HardwareType = b.Read16() d.Time = time.Duration(b.Read32()) * time.Second d.HardwareAddr = b.Remaining() return nil }
go
func (d *DUIDLLT) UnmarshalBinary(p []byte) error { b := buffer.New(p) // Too short to be valid DUIDLLT if b.Len() < 8 { return io.ErrUnexpectedEOF } // Verify DUID type dType := DUIDType(b.Read16()) if dType != DUIDTypeLLT { return errInvalidDUIDLLT } d.Type = dType d.HardwareType = b.Read16() d.Time = time.Duration(b.Read32()) * time.Second d.HardwareAddr = b.Remaining() return nil }
[ "func", "(", "d", "*", "DUIDLLT", ")", "UnmarshalBinary", "(", "p", "[", "]", "byte", ")", "error", "{", "b", ":=", "buffer", ".", "New", "(", "p", ")", "\n", "// Too short to be valid DUIDLLT", "if", "b", ".", "Len", "(", ")", "<", "8", "{", "return", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n\n", "// Verify DUID type", "dType", ":=", "DUIDType", "(", "b", ".", "Read16", "(", ")", ")", "\n", "if", "dType", "!=", "DUIDTypeLLT", "{", "return", "errInvalidDUIDLLT", "\n", "}", "\n", "d", ".", "Type", "=", "dType", "\n", "d", ".", "HardwareType", "=", "b", ".", "Read16", "(", ")", "\n", "d", ".", "Time", "=", "time", ".", "Duration", "(", "b", ".", "Read32", "(", ")", ")", "*", "time", ".", "Second", "\n\n", "d", ".", "HardwareAddr", "=", "b", ".", "Remaining", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary unmarshals a raw byte slice into a DUIDLLT. // If the byte slice does not contain enough data to form a valid // DUIDLLT, or another DUID type is indicated, errInvalidDUIDLLT is returned.
[ "UnmarshalBinary", "unmarshals", "a", "raw", "byte", "slice", "into", "a", "DUIDLLT", ".", "If", "the", "byte", "slice", "does", "not", "contain", "enough", "data", "to", "form", "a", "valid", "DUIDLLT", "or", "another", "DUID", "type", "is", "indicated", "errInvalidDUIDLLT", "is", "returned", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/duid.go#L159-L178
16,034
mdlayher/dhcp6
dhcp6opts/duid.go
NewDUIDEN
func NewDUIDEN(enterpriseNumber uint32, identifier []byte) *DUIDEN { return &DUIDEN{ Type: DUIDTypeEN, EnterpriseNumber: enterpriseNumber, Identifier: identifier, } }
go
func NewDUIDEN(enterpriseNumber uint32, identifier []byte) *DUIDEN { return &DUIDEN{ Type: DUIDTypeEN, EnterpriseNumber: enterpriseNumber, Identifier: identifier, } }
[ "func", "NewDUIDEN", "(", "enterpriseNumber", "uint32", ",", "identifier", "[", "]", "byte", ")", "*", "DUIDEN", "{", "return", "&", "DUIDEN", "{", "Type", ":", "DUIDTypeEN", ",", "EnterpriseNumber", ":", "enterpriseNumber", ",", "Identifier", ":", "identifier", ",", "}", "\n", "}" ]
// NewDUIDEN generates a new DUIDEN from an input IANA-assigned Private // Enterprise Number and a variable length unique identifier byte slice.
[ "NewDUIDEN", "generates", "a", "new", "DUIDEN", "from", "an", "input", "IANA", "-", "assigned", "Private", "Enterprise", "Number", "and", "a", "variable", "length", "unique", "identifier", "byte", "slice", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/duid.go#L199-L205
16,035
mdlayher/dhcp6
dhcp6opts/duid.go
MarshalBinary
func (d *DUIDEN) MarshalBinary() ([]byte, error) { // 2 bytes: DUID type // 4 bytes: enterprise number // N bytes: identifier b := buffer.New(nil) b.Write16(uint16(d.Type)) b.Write32(d.EnterpriseNumber) b.WriteBytes(d.Identifier) return b.Data(), nil }
go
func (d *DUIDEN) MarshalBinary() ([]byte, error) { // 2 bytes: DUID type // 4 bytes: enterprise number // N bytes: identifier b := buffer.New(nil) b.Write16(uint16(d.Type)) b.Write32(d.EnterpriseNumber) b.WriteBytes(d.Identifier) return b.Data(), nil }
[ "func", "(", "d", "*", "DUIDEN", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// 2 bytes: DUID type", "// 4 bytes: enterprise number", "// N bytes: identifier", "b", ":=", "buffer", ".", "New", "(", "nil", ")", "\n\n", "b", ".", "Write16", "(", "uint16", "(", "d", ".", "Type", ")", ")", "\n", "b", ".", "Write32", "(", "d", ".", "EnterpriseNumber", ")", "\n", "b", ".", "WriteBytes", "(", "d", ".", "Identifier", ")", "\n\n", "return", "b", ".", "Data", "(", ")", ",", "nil", "\n", "}" ]
// MarshalBinary allocates a byte slice containing the data from a DUIDEN.
[ "MarshalBinary", "allocates", "a", "byte", "slice", "containing", "the", "data", "from", "a", "DUIDEN", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/duid.go#L208-L219
16,036
mdlayher/dhcp6
dhcp6opts/duid.go
UnmarshalBinary
func (d *DUIDEN) UnmarshalBinary(p []byte) error { b := buffer.New(p) // Too short to be valid DUIDEN if b.Len() < 6 { return io.ErrUnexpectedEOF } // Verify DUID type dType := DUIDType(b.Read16()) if dType != DUIDTypeEN { return errInvalidDUIDEN } d.Type = dType d.EnterpriseNumber = b.Read32() d.Identifier = b.Remaining() return nil }
go
func (d *DUIDEN) UnmarshalBinary(p []byte) error { b := buffer.New(p) // Too short to be valid DUIDEN if b.Len() < 6 { return io.ErrUnexpectedEOF } // Verify DUID type dType := DUIDType(b.Read16()) if dType != DUIDTypeEN { return errInvalidDUIDEN } d.Type = dType d.EnterpriseNumber = b.Read32() d.Identifier = b.Remaining() return nil }
[ "func", "(", "d", "*", "DUIDEN", ")", "UnmarshalBinary", "(", "p", "[", "]", "byte", ")", "error", "{", "b", ":=", "buffer", ".", "New", "(", "p", ")", "\n", "// Too short to be valid DUIDEN", "if", "b", ".", "Len", "(", ")", "<", "6", "{", "return", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n\n", "// Verify DUID type", "dType", ":=", "DUIDType", "(", "b", ".", "Read16", "(", ")", ")", "\n", "if", "dType", "!=", "DUIDTypeEN", "{", "return", "errInvalidDUIDEN", "\n", "}", "\n", "d", ".", "Type", "=", "dType", "\n", "d", ".", "EnterpriseNumber", "=", "b", ".", "Read32", "(", ")", "\n", "d", ".", "Identifier", "=", "b", ".", "Remaining", "(", ")", "\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary unmarshals a raw byte slice into a DUIDEN. // If the byte slice does not contain enough data to form a valid // DUIDEN, or another DUID type is indicated, errInvalidDUIDEN is returned.
[ "UnmarshalBinary", "unmarshals", "a", "raw", "byte", "slice", "into", "a", "DUIDEN", ".", "If", "the", "byte", "slice", "does", "not", "contain", "enough", "data", "to", "form", "a", "valid", "DUIDEN", "or", "another", "DUID", "type", "is", "indicated", "errInvalidDUIDEN", "is", "returned", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/duid.go#L224-L240
16,037
mdlayher/dhcp6
dhcp6opts/duid.go
NewDUIDLL
func NewDUIDLL(hardwareType uint16, hardwareAddr net.HardwareAddr) *DUIDLL { return &DUIDLL{ Type: DUIDTypeLL, HardwareType: hardwareType, HardwareAddr: hardwareAddr, } }
go
func NewDUIDLL(hardwareType uint16, hardwareAddr net.HardwareAddr) *DUIDLL { return &DUIDLL{ Type: DUIDTypeLL, HardwareType: hardwareType, HardwareAddr: hardwareAddr, } }
[ "func", "NewDUIDLL", "(", "hardwareType", "uint16", ",", "hardwareAddr", "net", ".", "HardwareAddr", ")", "*", "DUIDLL", "{", "return", "&", "DUIDLL", "{", "Type", ":", "DUIDTypeLL", ",", "HardwareType", ":", "hardwareType", ",", "HardwareAddr", ":", "hardwareAddr", ",", "}", "\n", "}" ]
// NewDUIDLL generates a new DUIDLL from an input IANA-assigned hardware // type and a hardware address.
[ "NewDUIDLL", "generates", "a", "new", "DUIDLL", "from", "an", "input", "IANA", "-", "assigned", "hardware", "type", "and", "a", "hardware", "address", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/duid.go#L270-L276
16,038
mdlayher/dhcp6
dhcp6opts/duid.go
MarshalBinary
func (d *DUIDLL) MarshalBinary() ([]byte, error) { // 2 bytes: DUID type // 2 bytes: hardware type // N bytes: hardware address b := buffer.New(nil) b.Write16(uint16(d.Type)) b.Write16(d.HardwareType) b.WriteBytes(d.HardwareAddr) return b.Data(), nil }
go
func (d *DUIDLL) MarshalBinary() ([]byte, error) { // 2 bytes: DUID type // 2 bytes: hardware type // N bytes: hardware address b := buffer.New(nil) b.Write16(uint16(d.Type)) b.Write16(d.HardwareType) b.WriteBytes(d.HardwareAddr) return b.Data(), nil }
[ "func", "(", "d", "*", "DUIDLL", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// 2 bytes: DUID type", "// 2 bytes: hardware type", "// N bytes: hardware address", "b", ":=", "buffer", ".", "New", "(", "nil", ")", "\n\n", "b", ".", "Write16", "(", "uint16", "(", "d", ".", "Type", ")", ")", "\n", "b", ".", "Write16", "(", "d", ".", "HardwareType", ")", "\n", "b", ".", "WriteBytes", "(", "d", ".", "HardwareAddr", ")", "\n\n", "return", "b", ".", "Data", "(", ")", ",", "nil", "\n", "}" ]
// MarshalBinary allocates a byte slice containing the data from a DUIDLL.
[ "MarshalBinary", "allocates", "a", "byte", "slice", "containing", "the", "data", "from", "a", "DUIDLL", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/duid.go#L279-L290
16,039
mdlayher/dhcp6
dhcp6opts/duid.go
UnmarshalBinary
func (d *DUIDLL) UnmarshalBinary(p []byte) error { b := buffer.New(p) // Too short to be DUIDLL if b.Len() < 4 { return io.ErrUnexpectedEOF } // Verify DUID type dType := DUIDType(b.Read16()) if dType != DUIDTypeLL { return errInvalidDUIDLL } d.Type = dType d.HardwareType = b.Read16() d.HardwareAddr = b.Remaining() return nil }
go
func (d *DUIDLL) UnmarshalBinary(p []byte) error { b := buffer.New(p) // Too short to be DUIDLL if b.Len() < 4 { return io.ErrUnexpectedEOF } // Verify DUID type dType := DUIDType(b.Read16()) if dType != DUIDTypeLL { return errInvalidDUIDLL } d.Type = dType d.HardwareType = b.Read16() d.HardwareAddr = b.Remaining() return nil }
[ "func", "(", "d", "*", "DUIDLL", ")", "UnmarshalBinary", "(", "p", "[", "]", "byte", ")", "error", "{", "b", ":=", "buffer", ".", "New", "(", "p", ")", "\n", "// Too short to be DUIDLL", "if", "b", ".", "Len", "(", ")", "<", "4", "{", "return", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n\n", "// Verify DUID type", "dType", ":=", "DUIDType", "(", "b", ".", "Read16", "(", ")", ")", "\n", "if", "dType", "!=", "DUIDTypeLL", "{", "return", "errInvalidDUIDLL", "\n", "}", "\n", "d", ".", "Type", "=", "dType", "\n", "d", ".", "HardwareType", "=", "b", ".", "Read16", "(", ")", "\n", "d", ".", "HardwareAddr", "=", "b", ".", "Remaining", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary unmarshals a raw byte slice into a DUIDLL. // If the byte slice does not contain enough data to form a valid // DUIDLL, or another DUID type is indicated, errInvalidDUIDLL is returned.
[ "UnmarshalBinary", "unmarshals", "a", "raw", "byte", "slice", "into", "a", "DUIDLL", ".", "If", "the", "byte", "slice", "does", "not", "contain", "enough", "data", "to", "form", "a", "valid", "DUIDLL", "or", "another", "DUID", "type", "is", "indicated", "errInvalidDUIDLL", "is", "returned", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/duid.go#L295-L312
16,040
mdlayher/dhcp6
dhcp6opts/duid.go
MarshalBinary
func (d *DUIDUUID) MarshalBinary() ([]byte, error) { // 2 bytes: DUID type // 16 bytes: UUID b := buffer.New(nil) b.Write16(uint16(d.Type)) b.WriteBytes(d.UUID[:]) return b.Data(), nil }
go
func (d *DUIDUUID) MarshalBinary() ([]byte, error) { // 2 bytes: DUID type // 16 bytes: UUID b := buffer.New(nil) b.Write16(uint16(d.Type)) b.WriteBytes(d.UUID[:]) return b.Data(), nil }
[ "func", "(", "d", "*", "DUIDUUID", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// 2 bytes: DUID type", "// 16 bytes: UUID", "b", ":=", "buffer", ".", "New", "(", "nil", ")", "\n\n", "b", ".", "Write16", "(", "uint16", "(", "d", ".", "Type", ")", ")", "\n", "b", ".", "WriteBytes", "(", "d", ".", "UUID", "[", ":", "]", ")", "\n\n", "return", "b", ".", "Data", "(", ")", ",", "nil", "\n", "}" ]
// MarshalBinary allocates a byte slice containing the data from a DUIDUUID.
[ "MarshalBinary", "allocates", "a", "byte", "slice", "containing", "the", "data", "from", "a", "DUIDUUID", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/duid.go#L335-L344
16,041
mdlayher/dhcp6
dhcp6opts/duid.go
UnmarshalBinary
func (d *DUIDUUID) UnmarshalBinary(p []byte) error { b := buffer.New(p) // DUIDUUIDs are fixed-length structures if b.Len() != 18 { return io.ErrUnexpectedEOF } // Verify DUID type dType := DUIDType(b.Read16()) if dType != DUIDTypeUUID { return errInvalidDUIDUUID } d.Type = dType b.ReadBytes(d.UUID[:]) return nil }
go
func (d *DUIDUUID) UnmarshalBinary(p []byte) error { b := buffer.New(p) // DUIDUUIDs are fixed-length structures if b.Len() != 18 { return io.ErrUnexpectedEOF } // Verify DUID type dType := DUIDType(b.Read16()) if dType != DUIDTypeUUID { return errInvalidDUIDUUID } d.Type = dType b.ReadBytes(d.UUID[:]) return nil }
[ "func", "(", "d", "*", "DUIDUUID", ")", "UnmarshalBinary", "(", "p", "[", "]", "byte", ")", "error", "{", "b", ":=", "buffer", ".", "New", "(", "p", ")", "\n", "// DUIDUUIDs are fixed-length structures", "if", "b", ".", "Len", "(", ")", "!=", "18", "{", "return", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n\n", "// Verify DUID type", "dType", ":=", "DUIDType", "(", "b", ".", "Read16", "(", ")", ")", "\n", "if", "dType", "!=", "DUIDTypeUUID", "{", "return", "errInvalidDUIDUUID", "\n", "}", "\n", "d", ".", "Type", "=", "dType", "\n", "b", ".", "ReadBytes", "(", "d", ".", "UUID", "[", ":", "]", ")", "\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary unmarshals a raw byte slice into a DUIDUUID. // If the byte slice does not contain the exact number of bytes // needed to form a valid DUIDUUID, or another DUID type is indicated, // errInvalidDUIDUUID is returned.
[ "UnmarshalBinary", "unmarshals", "a", "raw", "byte", "slice", "into", "a", "DUIDUUID", ".", "If", "the", "byte", "slice", "does", "not", "contain", "the", "exact", "number", "of", "bytes", "needed", "to", "form", "a", "valid", "DUIDUUID", "or", "another", "DUID", "type", "is", "indicated", "errInvalidDUIDUUID", "is", "returned", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/duid.go#L350-L365
16,042
mdlayher/dhcp6
dhcp6opts/duid.go
parseDUID
func parseDUID(p []byte) (DUID, error) { b := buffer.New(p) // DUID must have enough bytes to determine its type if b.Len() < 2 { return nil, io.ErrUnexpectedEOF } var d DUID switch DUIDType(b.Read16()) { case DUIDTypeLLT: d = new(DUIDLLT) case DUIDTypeEN: d = new(DUIDEN) case DUIDTypeLL: d = new(DUIDLL) case DUIDTypeUUID: d = new(DUIDUUID) default: return nil, errUnknownDUID } return d, d.UnmarshalBinary(p) }
go
func parseDUID(p []byte) (DUID, error) { b := buffer.New(p) // DUID must have enough bytes to determine its type if b.Len() < 2 { return nil, io.ErrUnexpectedEOF } var d DUID switch DUIDType(b.Read16()) { case DUIDTypeLLT: d = new(DUIDLLT) case DUIDTypeEN: d = new(DUIDEN) case DUIDTypeLL: d = new(DUIDLL) case DUIDTypeUUID: d = new(DUIDUUID) default: return nil, errUnknownDUID } return d, d.UnmarshalBinary(p) }
[ "func", "parseDUID", "(", "p", "[", "]", "byte", ")", "(", "DUID", ",", "error", ")", "{", "b", ":=", "buffer", ".", "New", "(", "p", ")", "\n", "// DUID must have enough bytes to determine its type", "if", "b", ".", "Len", "(", ")", "<", "2", "{", "return", "nil", ",", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n\n", "var", "d", "DUID", "\n", "switch", "DUIDType", "(", "b", ".", "Read16", "(", ")", ")", "{", "case", "DUIDTypeLLT", ":", "d", "=", "new", "(", "DUIDLLT", ")", "\n", "case", "DUIDTypeEN", ":", "d", "=", "new", "(", "DUIDEN", ")", "\n", "case", "DUIDTypeLL", ":", "d", "=", "new", "(", "DUIDLL", ")", "\n", "case", "DUIDTypeUUID", ":", "d", "=", "new", "(", "DUIDUUID", ")", "\n", "default", ":", "return", "nil", ",", "errUnknownDUID", "\n", "}", "\n\n", "return", "d", ",", "d", ".", "UnmarshalBinary", "(", "p", ")", "\n", "}" ]
// parseDUID returns the correct DUID type of the input byte slice as a // DUID interface type.
[ "parseDUID", "returns", "the", "correct", "DUID", "type", "of", "the", "input", "byte", "slice", "as", "a", "DUID", "interface", "type", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/duid.go#L369-L391
16,043
mdlayher/dhcp6
dhcp6opts/iaaddr.go
NewIAAddr
func NewIAAddr(ip net.IP, preferred time.Duration, valid time.Duration, options dhcp6.Options) (*IAAddr, error) { // From documentation: If ip is not an IPv4 address, To4 returns nil. if ip.To4() != nil { return nil, ErrInvalidIP } // Preferred lifetime must always be less than valid lifetime. if preferred > valid { return nil, ErrInvalidLifetimes } // If no options set, make empty map if options == nil { options = make(dhcp6.Options) } return &IAAddr{ IP: ip, PreferredLifetime: preferred, ValidLifetime: valid, Options: options, }, nil }
go
func NewIAAddr(ip net.IP, preferred time.Duration, valid time.Duration, options dhcp6.Options) (*IAAddr, error) { // From documentation: If ip is not an IPv4 address, To4 returns nil. if ip.To4() != nil { return nil, ErrInvalidIP } // Preferred lifetime must always be less than valid lifetime. if preferred > valid { return nil, ErrInvalidLifetimes } // If no options set, make empty map if options == nil { options = make(dhcp6.Options) } return &IAAddr{ IP: ip, PreferredLifetime: preferred, ValidLifetime: valid, Options: options, }, nil }
[ "func", "NewIAAddr", "(", "ip", "net", ".", "IP", ",", "preferred", "time", ".", "Duration", ",", "valid", "time", ".", "Duration", ",", "options", "dhcp6", ".", "Options", ")", "(", "*", "IAAddr", ",", "error", ")", "{", "// From documentation: If ip is not an IPv4 address, To4 returns nil.", "if", "ip", ".", "To4", "(", ")", "!=", "nil", "{", "return", "nil", ",", "ErrInvalidIP", "\n", "}", "\n\n", "// Preferred lifetime must always be less than valid lifetime.", "if", "preferred", ">", "valid", "{", "return", "nil", ",", "ErrInvalidLifetimes", "\n", "}", "\n\n", "// If no options set, make empty map", "if", "options", "==", "nil", "{", "options", "=", "make", "(", "dhcp6", ".", "Options", ")", "\n", "}", "\n\n", "return", "&", "IAAddr", "{", "IP", ":", "ip", ",", "PreferredLifetime", ":", "preferred", ",", "ValidLifetime", ":", "valid", ",", "Options", ":", "options", ",", "}", ",", "nil", "\n", "}" ]
// NewIAAddr creates a new IAAddr from an IPv6 address, preferred and valid lifetime // durations, and an optional Options map. // // The IP must be exactly 16 bytes, the correct length for an IPv6 address. // The preferred lifetime duration must be less than the valid lifetime // duration. Failure to meet either of these conditions will result in an error. // If an Options map is not specified, a new one will be allocated.
[ "NewIAAddr", "creates", "a", "new", "IAAddr", "from", "an", "IPv6", "address", "preferred", "and", "valid", "lifetime", "durations", "and", "an", "optional", "Options", "map", ".", "The", "IP", "must", "be", "exactly", "16", "bytes", "the", "correct", "length", "for", "an", "IPv6", "address", ".", "The", "preferred", "lifetime", "duration", "must", "be", "less", "than", "the", "valid", "lifetime", "duration", ".", "Failure", "to", "meet", "either", "of", "these", "conditions", "will", "result", "in", "an", "error", ".", "If", "an", "Options", "map", "is", "not", "specified", "a", "new", "one", "will", "be", "allocated", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/iaaddr.go#L54-L76
16,044
mdlayher/dhcp6
dhcp6opts/iaaddr.go
MarshalBinary
func (i *IAAddr) MarshalBinary() ([]byte, error) { // 16 bytes: IPv6 address // 4 bytes: preferred lifetime // 4 bytes: valid lifetime // N bytes: options b := buffer.New(nil) copy(b.WriteN(net.IPv6len), i.IP) b.Write32(uint32(i.PreferredLifetime / time.Second)) b.Write32(uint32(i.ValidLifetime / time.Second)) opts, err := i.Options.MarshalBinary() if err != nil { return nil, err } b.WriteBytes(opts) return b.Data(), nil }
go
func (i *IAAddr) MarshalBinary() ([]byte, error) { // 16 bytes: IPv6 address // 4 bytes: preferred lifetime // 4 bytes: valid lifetime // N bytes: options b := buffer.New(nil) copy(b.WriteN(net.IPv6len), i.IP) b.Write32(uint32(i.PreferredLifetime / time.Second)) b.Write32(uint32(i.ValidLifetime / time.Second)) opts, err := i.Options.MarshalBinary() if err != nil { return nil, err } b.WriteBytes(opts) return b.Data(), nil }
[ "func", "(", "i", "*", "IAAddr", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// 16 bytes: IPv6 address", "// 4 bytes: preferred lifetime", "// 4 bytes: valid lifetime", "// N bytes: options", "b", ":=", "buffer", ".", "New", "(", "nil", ")", "\n\n", "copy", "(", "b", ".", "WriteN", "(", "net", ".", "IPv6len", ")", ",", "i", ".", "IP", ")", "\n", "b", ".", "Write32", "(", "uint32", "(", "i", ".", "PreferredLifetime", "/", "time", ".", "Second", ")", ")", "\n", "b", ".", "Write32", "(", "uint32", "(", "i", ".", "ValidLifetime", "/", "time", ".", "Second", ")", ")", "\n", "opts", ",", "err", ":=", "i", ".", "Options", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "b", ".", "WriteBytes", "(", "opts", ")", "\n\n", "return", "b", ".", "Data", "(", ")", ",", "nil", "\n", "}" ]
// MarshalBinary allocates a byte slice containing the data from a IAAddr.
[ "MarshalBinary", "allocates", "a", "byte", "slice", "containing", "the", "data", "from", "a", "IAAddr", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/iaaddr.go#L79-L96
16,045
mdlayher/dhcp6
dhcp6opts/iaaddr.go
UnmarshalBinary
func (i *IAAddr) UnmarshalBinary(p []byte) error { b := buffer.New(p) if b.Len() < 24 { return io.ErrUnexpectedEOF } i.IP = make(net.IP, net.IPv6len) copy(i.IP, b.Consume(net.IPv6len)) i.PreferredLifetime = time.Duration(b.Read32()) * time.Second i.ValidLifetime = time.Duration(b.Read32()) * time.Second // Preferred lifetime must always be less than valid lifetime. if i.PreferredLifetime > i.ValidLifetime { return ErrInvalidLifetimes } return (&i.Options).UnmarshalBinary(b.Remaining()) }
go
func (i *IAAddr) UnmarshalBinary(p []byte) error { b := buffer.New(p) if b.Len() < 24 { return io.ErrUnexpectedEOF } i.IP = make(net.IP, net.IPv6len) copy(i.IP, b.Consume(net.IPv6len)) i.PreferredLifetime = time.Duration(b.Read32()) * time.Second i.ValidLifetime = time.Duration(b.Read32()) * time.Second // Preferred lifetime must always be less than valid lifetime. if i.PreferredLifetime > i.ValidLifetime { return ErrInvalidLifetimes } return (&i.Options).UnmarshalBinary(b.Remaining()) }
[ "func", "(", "i", "*", "IAAddr", ")", "UnmarshalBinary", "(", "p", "[", "]", "byte", ")", "error", "{", "b", ":=", "buffer", ".", "New", "(", "p", ")", "\n", "if", "b", ".", "Len", "(", ")", "<", "24", "{", "return", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n\n", "i", ".", "IP", "=", "make", "(", "net", ".", "IP", ",", "net", ".", "IPv6len", ")", "\n", "copy", "(", "i", ".", "IP", ",", "b", ".", "Consume", "(", "net", ".", "IPv6len", ")", ")", "\n\n", "i", ".", "PreferredLifetime", "=", "time", ".", "Duration", "(", "b", ".", "Read32", "(", ")", ")", "*", "time", ".", "Second", "\n", "i", ".", "ValidLifetime", "=", "time", ".", "Duration", "(", "b", ".", "Read32", "(", ")", ")", "*", "time", ".", "Second", "\n\n", "// Preferred lifetime must always be less than valid lifetime.", "if", "i", ".", "PreferredLifetime", ">", "i", ".", "ValidLifetime", "{", "return", "ErrInvalidLifetimes", "\n", "}", "\n\n", "return", "(", "&", "i", ".", "Options", ")", ".", "UnmarshalBinary", "(", "b", ".", "Remaining", "(", ")", ")", "\n", "}" ]
// UnmarshalBinary unmarshals a raw byte slice into a IAAddr. // // If the byte slice does not contain enough data to form a valid IAAddr, // io.ErrUnexpectedEOF is returned. If the preferred lifetime value in the // byte slice is less than the valid lifetime, ErrInvalidLifetimes is returned.
[ "UnmarshalBinary", "unmarshals", "a", "raw", "byte", "slice", "into", "a", "IAAddr", ".", "If", "the", "byte", "slice", "does", "not", "contain", "enough", "data", "to", "form", "a", "valid", "IAAddr", "io", ".", "ErrUnexpectedEOF", "is", "returned", ".", "If", "the", "preferred", "lifetime", "value", "in", "the", "byte", "slice", "is", "less", "than", "the", "valid", "lifetime", "ErrInvalidLifetimes", "is", "returned", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/iaaddr.go#L103-L121
16,046
mdlayher/dhcp6
dhcp6opts/iata.go
NewIATA
func NewIATA(iaid [4]byte, options dhcp6.Options) *IATA { if options == nil { options = make(dhcp6.Options) } return &IATA{ IAID: iaid, Options: options, } }
go
func NewIATA(iaid [4]byte, options dhcp6.Options) *IATA { if options == nil { options = make(dhcp6.Options) } return &IATA{ IAID: iaid, Options: options, } }
[ "func", "NewIATA", "(", "iaid", "[", "4", "]", "byte", ",", "options", "dhcp6", ".", "Options", ")", "*", "IATA", "{", "if", "options", "==", "nil", "{", "options", "=", "make", "(", "dhcp6", ".", "Options", ")", "\n", "}", "\n\n", "return", "&", "IATA", "{", "IAID", ":", "iaid", ",", "Options", ":", "options", ",", "}", "\n", "}" ]
// NewIATA creates a new IATA from an IAID and an Options map. If an Options // map is not specified, a new one will be allocated.
[ "NewIATA", "creates", "a", "new", "IATA", "from", "an", "IAID", "and", "an", "Options", "map", ".", "If", "an", "Options", "map", "is", "not", "specified", "a", "new", "one", "will", "be", "allocated", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/iata.go#L27-L36
16,047
mdlayher/dhcp6
dhcp6opts/iata.go
MarshalBinary
func (i *IATA) MarshalBinary() ([]byte, error) { // 4 bytes: IAID // N bytes: options slice byte count b := buffer.New(nil) b.WriteBytes(i.IAID[:]) opts, err := i.Options.MarshalBinary() if err != nil { return nil, err } b.WriteBytes(opts) return b.Data(), nil }
go
func (i *IATA) MarshalBinary() ([]byte, error) { // 4 bytes: IAID // N bytes: options slice byte count b := buffer.New(nil) b.WriteBytes(i.IAID[:]) opts, err := i.Options.MarshalBinary() if err != nil { return nil, err } b.WriteBytes(opts) return b.Data(), nil }
[ "func", "(", "i", "*", "IATA", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// 4 bytes: IAID", "// N bytes: options slice byte count", "b", ":=", "buffer", ".", "New", "(", "nil", ")", "\n\n", "b", ".", "WriteBytes", "(", "i", ".", "IAID", "[", ":", "]", ")", "\n", "opts", ",", "err", ":=", "i", ".", "Options", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "b", ".", "WriteBytes", "(", "opts", ")", "\n\n", "return", "b", ".", "Data", "(", ")", ",", "nil", "\n", "}" ]
// MarshalBinary allocates a byte slice containing the data from a IATA.
[ "MarshalBinary", "allocates", "a", "byte", "slice", "containing", "the", "data", "from", "a", "IATA", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/iata.go#L39-L52
16,048
mdlayher/dhcp6
dhcp6opts/iata.go
UnmarshalBinary
func (i *IATA) UnmarshalBinary(p []byte) error { b := buffer.New(p) // IATA must contain at least an IAID. if b.Len() < 4 { return io.ErrUnexpectedEOF } b.ReadBytes(i.IAID[:]) return (&i.Options).UnmarshalBinary(b.Remaining()) }
go
func (i *IATA) UnmarshalBinary(p []byte) error { b := buffer.New(p) // IATA must contain at least an IAID. if b.Len() < 4 { return io.ErrUnexpectedEOF } b.ReadBytes(i.IAID[:]) return (&i.Options).UnmarshalBinary(b.Remaining()) }
[ "func", "(", "i", "*", "IATA", ")", "UnmarshalBinary", "(", "p", "[", "]", "byte", ")", "error", "{", "b", ":=", "buffer", ".", "New", "(", "p", ")", "\n", "// IATA must contain at least an IAID.", "if", "b", ".", "Len", "(", ")", "<", "4", "{", "return", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n\n", "b", ".", "ReadBytes", "(", "i", ".", "IAID", "[", ":", "]", ")", "\n", "return", "(", "&", "i", ".", "Options", ")", ".", "UnmarshalBinary", "(", "b", ".", "Remaining", "(", ")", ")", "\n", "}" ]
// UnmarshalBinary unmarshals a raw byte slice into a IATA. // // If the byte slice does not contain enough data to form a valid IATA, // io.ErrUnexpectedEOF is returned.
[ "UnmarshalBinary", "unmarshals", "a", "raw", "byte", "slice", "into", "a", "IATA", ".", "If", "the", "byte", "slice", "does", "not", "contain", "enough", "data", "to", "form", "a", "valid", "IATA", "io", ".", "ErrUnexpectedEOF", "is", "returned", "." ]
2a67805d7d0b0bad6c1103058981afdea583b459
https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/iata.go#L58-L67
16,049
paypal/gorealis
retry.go
thriftCallWithRetries
func (r *realisClient) thriftCallWithRetries(thriftCall auroraThriftCall) (*aurora.Response, error) { var resp *aurora.Response var clientErr error var curStep int backoff := r.config.backoff duration := backoff.Duration for curStep = 0; curStep < backoff.Steps; curStep++ { // If this isn't our first try, backoff before the next try. if curStep != 0 { adjusted := duration if backoff.Jitter > 0.0 { adjusted = Jitter(duration, backoff.Jitter) } r.logger.Printf("A retriable error occurred during thrift call, backing off for %v before retry %v\n", adjusted, curStep) time.Sleep(adjusted) duration = time.Duration(float64(duration) * backoff.Factor) } // Only allow one go-routine make use or modify the thrift client connection. // Placing this in an anonymous function in order to create a new, short-lived stack allowing unlock // to be run in case of a panic inside of thriftCall. func() { r.lock.Lock() defer r.lock.Unlock() resp, clientErr = thriftCall() r.logger.TracePrintf("Aurora Thrift Call ended resp: %v clientErr: %v\n", resp, clientErr) }() // Check if our thrift call is returning an error. This is a retriable event as we don't know // if it was caused by network issues. if clientErr != nil { // Print out the error to the user r.logger.Printf("Client Error: %v\n", clientErr) // Determine if error is a temporary URL error by going up the stack e, ok := clientErr.(thrift.TTransportException) if ok { r.logger.DebugPrint("Encountered a transport exception") e, ok := e.Err().(*url.Error) if ok { // EOF error occurs when the server closes the read buffer of the client. This is common // when the server is overloaded and should be retried. All other errors that are permanent // will not be retried. if e.Err != io.EOF && !e.Temporary() { return nil, errors.Wrap(clientErr, "Permanent connection error") } } } // In the future, reestablish connection should be able to check if it is actually possible // to make a thrift call to Aurora. For now, a reconnect should always lead to a retry. r.ReestablishConn() } else { // If there was no client error, but the response is nil, something went wrong. // Ideally, we'll never encounter this but we're placing a safeguard here. if resp == nil { return nil, errors.New("Response from aurora is nil") } // Check Response Code from thrift and make a decision to continue retrying or not. switch responseCode := resp.GetResponseCode(); responseCode { // If the thrift call succeeded, stop retrying case aurora.ResponseCode_OK: return resp, nil // If the response code is transient, continue retrying case aurora.ResponseCode_ERROR_TRANSIENT: r.logger.Println("Aurora replied with Transient error code, retrying") continue // Failure scenarios, these indicate a bad payload or a bad config. Stop retrying. case aurora.ResponseCode_INVALID_REQUEST, aurora.ResponseCode_ERROR, aurora.ResponseCode_AUTH_FAILED, aurora.ResponseCode_JOB_UPDATING_ERROR: r.logger.Printf("Terminal Response Code %v from Aurora, won't retry\n", resp.GetResponseCode().String()) return resp, errors.New(response.CombineMessage(resp)) // The only case that should fall down to here is a WARNING response code. // It is currently not used as a response in the scheduler so it is unknown how to handle it. default: r.logger.DebugPrintf("unhandled response code %v received from Aurora\n", responseCode) return nil, errors.Errorf("unhandled response code from Aurora %v\n", responseCode.String()) } } } r.logger.DebugPrintf("it took %v retries to complete this operation\n", curStep) if curStep > 1 { r.config.logger.Printf("retried this thrift call %d time(s)", curStep) } // Provide more information to the user wherever possible. if clientErr != nil { return nil, newRetryError(errors.Wrap(clientErr, "ran out of retries, including latest error"), curStep) } else { return nil, newRetryError(errors.New("ran out of retries"), curStep) } }
go
func (r *realisClient) thriftCallWithRetries(thriftCall auroraThriftCall) (*aurora.Response, error) { var resp *aurora.Response var clientErr error var curStep int backoff := r.config.backoff duration := backoff.Duration for curStep = 0; curStep < backoff.Steps; curStep++ { // If this isn't our first try, backoff before the next try. if curStep != 0 { adjusted := duration if backoff.Jitter > 0.0 { adjusted = Jitter(duration, backoff.Jitter) } r.logger.Printf("A retriable error occurred during thrift call, backing off for %v before retry %v\n", adjusted, curStep) time.Sleep(adjusted) duration = time.Duration(float64(duration) * backoff.Factor) } // Only allow one go-routine make use or modify the thrift client connection. // Placing this in an anonymous function in order to create a new, short-lived stack allowing unlock // to be run in case of a panic inside of thriftCall. func() { r.lock.Lock() defer r.lock.Unlock() resp, clientErr = thriftCall() r.logger.TracePrintf("Aurora Thrift Call ended resp: %v clientErr: %v\n", resp, clientErr) }() // Check if our thrift call is returning an error. This is a retriable event as we don't know // if it was caused by network issues. if clientErr != nil { // Print out the error to the user r.logger.Printf("Client Error: %v\n", clientErr) // Determine if error is a temporary URL error by going up the stack e, ok := clientErr.(thrift.TTransportException) if ok { r.logger.DebugPrint("Encountered a transport exception") e, ok := e.Err().(*url.Error) if ok { // EOF error occurs when the server closes the read buffer of the client. This is common // when the server is overloaded and should be retried. All other errors that are permanent // will not be retried. if e.Err != io.EOF && !e.Temporary() { return nil, errors.Wrap(clientErr, "Permanent connection error") } } } // In the future, reestablish connection should be able to check if it is actually possible // to make a thrift call to Aurora. For now, a reconnect should always lead to a retry. r.ReestablishConn() } else { // If there was no client error, but the response is nil, something went wrong. // Ideally, we'll never encounter this but we're placing a safeguard here. if resp == nil { return nil, errors.New("Response from aurora is nil") } // Check Response Code from thrift and make a decision to continue retrying or not. switch responseCode := resp.GetResponseCode(); responseCode { // If the thrift call succeeded, stop retrying case aurora.ResponseCode_OK: return resp, nil // If the response code is transient, continue retrying case aurora.ResponseCode_ERROR_TRANSIENT: r.logger.Println("Aurora replied with Transient error code, retrying") continue // Failure scenarios, these indicate a bad payload or a bad config. Stop retrying. case aurora.ResponseCode_INVALID_REQUEST, aurora.ResponseCode_ERROR, aurora.ResponseCode_AUTH_FAILED, aurora.ResponseCode_JOB_UPDATING_ERROR: r.logger.Printf("Terminal Response Code %v from Aurora, won't retry\n", resp.GetResponseCode().String()) return resp, errors.New(response.CombineMessage(resp)) // The only case that should fall down to here is a WARNING response code. // It is currently not used as a response in the scheduler so it is unknown how to handle it. default: r.logger.DebugPrintf("unhandled response code %v received from Aurora\n", responseCode) return nil, errors.Errorf("unhandled response code from Aurora %v\n", responseCode.String()) } } } r.logger.DebugPrintf("it took %v retries to complete this operation\n", curStep) if curStep > 1 { r.config.logger.Printf("retried this thrift call %d time(s)", curStep) } // Provide more information to the user wherever possible. if clientErr != nil { return nil, newRetryError(errors.Wrap(clientErr, "ran out of retries, including latest error"), curStep) } else { return nil, newRetryError(errors.New("ran out of retries"), curStep) } }
[ "func", "(", "r", "*", "realisClient", ")", "thriftCallWithRetries", "(", "thriftCall", "auroraThriftCall", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "var", "resp", "*", "aurora", ".", "Response", "\n", "var", "clientErr", "error", "\n", "var", "curStep", "int", "\n\n", "backoff", ":=", "r", ".", "config", ".", "backoff", "\n", "duration", ":=", "backoff", ".", "Duration", "\n\n", "for", "curStep", "=", "0", ";", "curStep", "<", "backoff", ".", "Steps", ";", "curStep", "++", "{", "// If this isn't our first try, backoff before the next try.", "if", "curStep", "!=", "0", "{", "adjusted", ":=", "duration", "\n", "if", "backoff", ".", "Jitter", ">", "0.0", "{", "adjusted", "=", "Jitter", "(", "duration", ",", "backoff", ".", "Jitter", ")", "\n", "}", "\n\n", "r", ".", "logger", ".", "Printf", "(", "\"", "\\n", "\"", ",", "adjusted", ",", "curStep", ")", "\n\n", "time", ".", "Sleep", "(", "adjusted", ")", "\n", "duration", "=", "time", ".", "Duration", "(", "float64", "(", "duration", ")", "*", "backoff", ".", "Factor", ")", "\n", "}", "\n\n", "// Only allow one go-routine make use or modify the thrift client connection.", "// Placing this in an anonymous function in order to create a new, short-lived stack allowing unlock", "// to be run in case of a panic inside of thriftCall.", "func", "(", ")", "{", "r", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "resp", ",", "clientErr", "=", "thriftCall", "(", ")", "\n\n", "r", ".", "logger", ".", "TracePrintf", "(", "\"", "\\n", "\"", ",", "resp", ",", "clientErr", ")", "\n", "}", "(", ")", "\n\n", "// Check if our thrift call is returning an error. This is a retriable event as we don't know", "// if it was caused by network issues.", "if", "clientErr", "!=", "nil", "{", "// Print out the error to the user", "r", ".", "logger", ".", "Printf", "(", "\"", "\\n", "\"", ",", "clientErr", ")", "\n\n", "// Determine if error is a temporary URL error by going up the stack", "e", ",", "ok", ":=", "clientErr", ".", "(", "thrift", ".", "TTransportException", ")", "\n", "if", "ok", "{", "r", ".", "logger", ".", "DebugPrint", "(", "\"", "\"", ")", "\n\n", "e", ",", "ok", ":=", "e", ".", "Err", "(", ")", ".", "(", "*", "url", ".", "Error", ")", "\n", "if", "ok", "{", "// EOF error occurs when the server closes the read buffer of the client. This is common", "// when the server is overloaded and should be retried. All other errors that are permanent", "// will not be retried.", "if", "e", ".", "Err", "!=", "io", ".", "EOF", "&&", "!", "e", ".", "Temporary", "(", ")", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "clientErr", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// In the future, reestablish connection should be able to check if it is actually possible", "// to make a thrift call to Aurora. For now, a reconnect should always lead to a retry.", "r", ".", "ReestablishConn", "(", ")", "\n\n", "}", "else", "{", "// If there was no client error, but the response is nil, something went wrong.", "// Ideally, we'll never encounter this but we're placing a safeguard here.", "if", "resp", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Check Response Code from thrift and make a decision to continue retrying or not.", "switch", "responseCode", ":=", "resp", ".", "GetResponseCode", "(", ")", ";", "responseCode", "{", "// If the thrift call succeeded, stop retrying", "case", "aurora", ".", "ResponseCode_OK", ":", "return", "resp", ",", "nil", "\n\n", "// If the response code is transient, continue retrying", "case", "aurora", ".", "ResponseCode_ERROR_TRANSIENT", ":", "r", ".", "logger", ".", "Println", "(", "\"", "\"", ")", "\n", "continue", "\n\n", "// Failure scenarios, these indicate a bad payload or a bad config. Stop retrying.", "case", "aurora", ".", "ResponseCode_INVALID_REQUEST", ",", "aurora", ".", "ResponseCode_ERROR", ",", "aurora", ".", "ResponseCode_AUTH_FAILED", ",", "aurora", ".", "ResponseCode_JOB_UPDATING_ERROR", ":", "r", ".", "logger", ".", "Printf", "(", "\"", "\\n", "\"", ",", "resp", ".", "GetResponseCode", "(", ")", ".", "String", "(", ")", ")", "\n", "return", "resp", ",", "errors", ".", "New", "(", "response", ".", "CombineMessage", "(", "resp", ")", ")", "\n\n", "// The only case that should fall down to here is a WARNING response code.", "// It is currently not used as a response in the scheduler so it is unknown how to handle it.", "default", ":", "r", ".", "logger", ".", "DebugPrintf", "(", "\"", "\\n", "\"", ",", "responseCode", ")", "\n", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\\n", "\"", ",", "responseCode", ".", "String", "(", ")", ")", "\n", "}", "\n", "}", "\n\n", "}", "\n\n", "r", ".", "logger", ".", "DebugPrintf", "(", "\"", "\\n", "\"", ",", "curStep", ")", "\n\n", "if", "curStep", ">", "1", "{", "r", ".", "config", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "curStep", ")", "\n", "}", "\n\n", "// Provide more information to the user wherever possible.", "if", "clientErr", "!=", "nil", "{", "return", "nil", ",", "newRetryError", "(", "errors", ".", "Wrap", "(", "clientErr", ",", "\"", "\"", ")", ",", "curStep", ")", "\n", "}", "else", "{", "return", "nil", ",", "newRetryError", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "curStep", ")", "\n", "}", "\n", "}" ]
// Duplicates the functionality of ExponentialBackoff but is specifically targeted towards ThriftCalls.
[ "Duplicates", "the", "functionality", "of", "ExponentialBackoff", "but", "is", "specifically", "targeted", "towards", "ThriftCalls", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/retry.go#L119-L231
16,050
paypal/gorealis
zk.go
LeaderFromZK
func LeaderFromZK(cluster Cluster) (string, error) { return LeaderFromZKOpts(ZKEndpoints(strings.Split(cluster.ZK, ",")...), ZKPath(cluster.SchedZKPath)) }
go
func LeaderFromZK(cluster Cluster) (string, error) { return LeaderFromZKOpts(ZKEndpoints(strings.Split(cluster.ZK, ",")...), ZKPath(cluster.SchedZKPath)) }
[ "func", "LeaderFromZK", "(", "cluster", "Cluster", ")", "(", "string", ",", "error", ")", "{", "return", "LeaderFromZKOpts", "(", "ZKEndpoints", "(", "strings", ".", "Split", "(", "cluster", ".", "ZK", ",", "\"", "\"", ")", "...", ")", ",", "ZKPath", "(", "cluster", ".", "SchedZKPath", ")", ")", "\n", "}" ]
// Retrieves current Aurora leader from ZK.
[ "Retrieves", "current", "Aurora", "leader", "from", "ZK", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/zk.go#L79-L81
16,051
paypal/gorealis
monitors.go
JobUpdate
func (m *Monitor) JobUpdate(updateKey aurora.JobUpdateKey, interval int, timeout int) (bool, error) { status, err := m.JobUpdateStatus(updateKey, map[aurora.JobUpdateStatus]bool{ aurora.JobUpdateStatus_ROLLED_FORWARD: true, aurora.JobUpdateStatus_ROLLED_BACK: true, aurora.JobUpdateStatus_ABORTED: true, aurora.JobUpdateStatus_ERROR: true, aurora.JobUpdateStatus_FAILED: true, }, time.Duration(interval)*time.Second, time.Duration(timeout)*time.Second) if err != nil { return false, err } m.Client.RealisConfig().logger.Printf("job update status: %v\n", status) // Rolled forward is the only state in which an update has been successfully updated // if we encounter an inactive state and it is not at rolled forward, update failed switch status { case aurora.JobUpdateStatus_ROLLED_FORWARD: return true, nil case aurora.JobUpdateStatus_ROLLED_BACK, aurora.JobUpdateStatus_ABORTED, aurora.JobUpdateStatus_ERROR, aurora.JobUpdateStatus_FAILED: return false, errors.Errorf("bad terminal state for update: %v", status) default: return false, errors.Errorf("unexpected update state: %v", status) } }
go
func (m *Monitor) JobUpdate(updateKey aurora.JobUpdateKey, interval int, timeout int) (bool, error) { status, err := m.JobUpdateStatus(updateKey, map[aurora.JobUpdateStatus]bool{ aurora.JobUpdateStatus_ROLLED_FORWARD: true, aurora.JobUpdateStatus_ROLLED_BACK: true, aurora.JobUpdateStatus_ABORTED: true, aurora.JobUpdateStatus_ERROR: true, aurora.JobUpdateStatus_FAILED: true, }, time.Duration(interval)*time.Second, time.Duration(timeout)*time.Second) if err != nil { return false, err } m.Client.RealisConfig().logger.Printf("job update status: %v\n", status) // Rolled forward is the only state in which an update has been successfully updated // if we encounter an inactive state and it is not at rolled forward, update failed switch status { case aurora.JobUpdateStatus_ROLLED_FORWARD: return true, nil case aurora.JobUpdateStatus_ROLLED_BACK, aurora.JobUpdateStatus_ABORTED, aurora.JobUpdateStatus_ERROR, aurora.JobUpdateStatus_FAILED: return false, errors.Errorf("bad terminal state for update: %v", status) default: return false, errors.Errorf("unexpected update state: %v", status) } }
[ "func", "(", "m", "*", "Monitor", ")", "JobUpdate", "(", "updateKey", "aurora", ".", "JobUpdateKey", ",", "interval", "int", ",", "timeout", "int", ")", "(", "bool", ",", "error", ")", "{", "status", ",", "err", ":=", "m", ".", "JobUpdateStatus", "(", "updateKey", ",", "map", "[", "aurora", ".", "JobUpdateStatus", "]", "bool", "{", "aurora", ".", "JobUpdateStatus_ROLLED_FORWARD", ":", "true", ",", "aurora", ".", "JobUpdateStatus_ROLLED_BACK", ":", "true", ",", "aurora", ".", "JobUpdateStatus_ABORTED", ":", "true", ",", "aurora", ".", "JobUpdateStatus_ERROR", ":", "true", ",", "aurora", ".", "JobUpdateStatus_FAILED", ":", "true", ",", "}", ",", "time", ".", "Duration", "(", "interval", ")", "*", "time", ".", "Second", ",", "time", ".", "Duration", "(", "timeout", ")", "*", "time", ".", "Second", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "m", ".", "Client", ".", "RealisConfig", "(", ")", ".", "logger", ".", "Printf", "(", "\"", "\\n", "\"", ",", "status", ")", "\n\n", "// Rolled forward is the only state in which an update has been successfully updated", "// if we encounter an inactive state and it is not at rolled forward, update failed", "switch", "status", "{", "case", "aurora", ".", "JobUpdateStatus_ROLLED_FORWARD", ":", "return", "true", ",", "nil", "\n", "case", "aurora", ".", "JobUpdateStatus_ROLLED_BACK", ",", "aurora", ".", "JobUpdateStatus_ABORTED", ",", "aurora", ".", "JobUpdateStatus_ERROR", ",", "aurora", ".", "JobUpdateStatus_FAILED", ":", "return", "false", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "status", ")", "\n", "default", ":", "return", "false", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "status", ")", "\n", "}", "\n", "}" ]
// Polls the scheduler every certain amount of time to see if the update has succeeded
[ "Polls", "the", "scheduler", "every", "certain", "amount", "of", "time", "to", "see", "if", "the", "update", "has", "succeeded" ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/monitors.go#L31-L60
16,052
paypal/gorealis
monitors.go
Instances
func (m *Monitor) Instances(key *aurora.JobKey, instances int32, interval, timeout int) (bool, error) { return m.ScheduleStatus(key, instances, LiveStates, interval, timeout) }
go
func (m *Monitor) Instances(key *aurora.JobKey, instances int32, interval, timeout int) (bool, error) { return m.ScheduleStatus(key, instances, LiveStates, interval, timeout) }
[ "func", "(", "m", "*", "Monitor", ")", "Instances", "(", "key", "*", "aurora", ".", "JobKey", ",", "instances", "int32", ",", "interval", ",", "timeout", "int", ")", "(", "bool", ",", "error", ")", "{", "return", "m", ".", "ScheduleStatus", "(", "key", ",", "instances", ",", "LiveStates", ",", "interval", ",", "timeout", ")", "\n", "}" ]
// Monitor a Job until all instances enter one of the LIVE_STATES
[ "Monitor", "a", "Job", "until", "all", "instances", "enter", "one", "of", "the", "LIVE_STATES" ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/monitors.go#L105-L107
16,053
paypal/gorealis
updatejob.go
NewDefaultUpdateJob
func NewDefaultUpdateJob(config *aurora.TaskConfig) *UpdateJob { req := aurora.NewJobUpdateRequest() req.TaskConfig = config req.Settings = NewUpdateSettings() job := NewJob().(*AuroraJob) job.jobConfig.TaskConfig = config // Rebuild resource map from TaskConfig for _, ptr := range config.Resources { if ptr.NumCpus != nil { job.resources[CPU].NumCpus = ptr.NumCpus continue // Guard against Union violations that Go won't enforce } if ptr.RamMb != nil { job.resources[RAM].RamMb = ptr.RamMb continue } if ptr.DiskMb != nil { job.resources[DISK].DiskMb = ptr.DiskMb continue } if ptr.NumGpus != nil { job.resources[GPU] = &aurora.Resource{NumGpus: ptr.NumGpus} continue } } // Mirrors defaults set by Pystachio req.Settings.UpdateGroupSize = 1 req.Settings.WaitForBatchCompletion = false req.Settings.MinWaitInInstanceRunningMs = 45000 req.Settings.MaxPerInstanceFailures = 0 req.Settings.MaxFailedInstances = 0 req.Settings.RollbackOnFailure = true //TODO(rdelvalle): Deep copy job struct to avoid unexpected behavior return &UpdateJob{Job: job, req: req} }
go
func NewDefaultUpdateJob(config *aurora.TaskConfig) *UpdateJob { req := aurora.NewJobUpdateRequest() req.TaskConfig = config req.Settings = NewUpdateSettings() job := NewJob().(*AuroraJob) job.jobConfig.TaskConfig = config // Rebuild resource map from TaskConfig for _, ptr := range config.Resources { if ptr.NumCpus != nil { job.resources[CPU].NumCpus = ptr.NumCpus continue // Guard against Union violations that Go won't enforce } if ptr.RamMb != nil { job.resources[RAM].RamMb = ptr.RamMb continue } if ptr.DiskMb != nil { job.resources[DISK].DiskMb = ptr.DiskMb continue } if ptr.NumGpus != nil { job.resources[GPU] = &aurora.Resource{NumGpus: ptr.NumGpus} continue } } // Mirrors defaults set by Pystachio req.Settings.UpdateGroupSize = 1 req.Settings.WaitForBatchCompletion = false req.Settings.MinWaitInInstanceRunningMs = 45000 req.Settings.MaxPerInstanceFailures = 0 req.Settings.MaxFailedInstances = 0 req.Settings.RollbackOnFailure = true //TODO(rdelvalle): Deep copy job struct to avoid unexpected behavior return &UpdateJob{Job: job, req: req} }
[ "func", "NewDefaultUpdateJob", "(", "config", "*", "aurora", ".", "TaskConfig", ")", "*", "UpdateJob", "{", "req", ":=", "aurora", ".", "NewJobUpdateRequest", "(", ")", "\n", "req", ".", "TaskConfig", "=", "config", "\n", "req", ".", "Settings", "=", "NewUpdateSettings", "(", ")", "\n\n", "job", ":=", "NewJob", "(", ")", ".", "(", "*", "AuroraJob", ")", "\n", "job", ".", "jobConfig", ".", "TaskConfig", "=", "config", "\n\n", "// Rebuild resource map from TaskConfig", "for", "_", ",", "ptr", ":=", "range", "config", ".", "Resources", "{", "if", "ptr", ".", "NumCpus", "!=", "nil", "{", "job", ".", "resources", "[", "CPU", "]", ".", "NumCpus", "=", "ptr", ".", "NumCpus", "\n", "continue", "// Guard against Union violations that Go won't enforce", "\n", "}", "\n\n", "if", "ptr", ".", "RamMb", "!=", "nil", "{", "job", ".", "resources", "[", "RAM", "]", ".", "RamMb", "=", "ptr", ".", "RamMb", "\n", "continue", "\n", "}", "\n\n", "if", "ptr", ".", "DiskMb", "!=", "nil", "{", "job", ".", "resources", "[", "DISK", "]", ".", "DiskMb", "=", "ptr", ".", "DiskMb", "\n", "continue", "\n", "}", "\n\n", "if", "ptr", ".", "NumGpus", "!=", "nil", "{", "job", ".", "resources", "[", "GPU", "]", "=", "&", "aurora", ".", "Resource", "{", "NumGpus", ":", "ptr", ".", "NumGpus", "}", "\n", "continue", "\n", "}", "\n", "}", "\n\n", "// Mirrors defaults set by Pystachio", "req", ".", "Settings", ".", "UpdateGroupSize", "=", "1", "\n", "req", ".", "Settings", ".", "WaitForBatchCompletion", "=", "false", "\n", "req", ".", "Settings", ".", "MinWaitInInstanceRunningMs", "=", "45000", "\n", "req", ".", "Settings", ".", "MaxPerInstanceFailures", "=", "0", "\n", "req", ".", "Settings", ".", "MaxFailedInstances", "=", "0", "\n", "req", ".", "Settings", ".", "RollbackOnFailure", "=", "true", "\n\n", "//TODO(rdelvalle): Deep copy job struct to avoid unexpected behavior", "return", "&", "UpdateJob", "{", "Job", ":", "job", ",", "req", ":", "req", "}", "\n", "}" ]
// Create a default UpdateJob object.
[ "Create", "a", "default", "UpdateJob", "object", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/updatejob.go#L28-L70
16,054
paypal/gorealis
updatejob.go
InstanceCount
func (u *UpdateJob) InstanceCount(inst int32) *UpdateJob { u.req.InstanceCount = inst return u }
go
func (u *UpdateJob) InstanceCount(inst int32) *UpdateJob { u.req.InstanceCount = inst return u }
[ "func", "(", "u", "*", "UpdateJob", ")", "InstanceCount", "(", "inst", "int32", ")", "*", "UpdateJob", "{", "u", ".", "req", ".", "InstanceCount", "=", "inst", "\n", "return", "u", "\n", "}" ]
// Set instance count the job will have after the update.
[ "Set", "instance", "count", "the", "job", "will", "have", "after", "the", "update", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/updatejob.go#L110-L113
16,055
paypal/gorealis
updatejob.go
BatchSize
func (u *UpdateJob) BatchSize(size int32) *UpdateJob { u.req.Settings.UpdateGroupSize = size return u }
go
func (u *UpdateJob) BatchSize(size int32) *UpdateJob { u.req.Settings.UpdateGroupSize = size return u }
[ "func", "(", "u", "*", "UpdateJob", ")", "BatchSize", "(", "size", "int32", ")", "*", "UpdateJob", "{", "u", ".", "req", ".", "Settings", ".", "UpdateGroupSize", "=", "size", "\n", "return", "u", "\n", "}" ]
// Max number of instances being updated at any given moment.
[ "Max", "number", "of", "instances", "being", "updated", "at", "any", "given", "moment", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/updatejob.go#L116-L119
16,056
paypal/gorealis
updatejob.go
WatchTime
func (u *UpdateJob) WatchTime(ms int32) *UpdateJob { u.req.Settings.MinWaitInInstanceRunningMs = ms return u }
go
func (u *UpdateJob) WatchTime(ms int32) *UpdateJob { u.req.Settings.MinWaitInInstanceRunningMs = ms return u }
[ "func", "(", "u", "*", "UpdateJob", ")", "WatchTime", "(", "ms", "int32", ")", "*", "UpdateJob", "{", "u", ".", "req", ".", "Settings", ".", "MinWaitInInstanceRunningMs", "=", "ms", "\n", "return", "u", "\n", "}" ]
// Minimum number of seconds a shard must remain in RUNNING state before considered a success.
[ "Minimum", "number", "of", "seconds", "a", "shard", "must", "remain", "in", "RUNNING", "state", "before", "considered", "a", "success", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/updatejob.go#L122-L125
16,057
paypal/gorealis
updatejob.go
WaitForBatchCompletion
func (u *UpdateJob) WaitForBatchCompletion(batchWait bool) *UpdateJob { u.req.Settings.WaitForBatchCompletion = batchWait return u }
go
func (u *UpdateJob) WaitForBatchCompletion(batchWait bool) *UpdateJob { u.req.Settings.WaitForBatchCompletion = batchWait return u }
[ "func", "(", "u", "*", "UpdateJob", ")", "WaitForBatchCompletion", "(", "batchWait", "bool", ")", "*", "UpdateJob", "{", "u", ".", "req", ".", "Settings", ".", "WaitForBatchCompletion", "=", "batchWait", "\n", "return", "u", "\n", "}" ]
// Wait for all instances in a group to be done before moving on.
[ "Wait", "for", "all", "instances", "in", "a", "group", "to", "be", "done", "before", "moving", "on", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/updatejob.go#L128-L131
16,058
paypal/gorealis
updatejob.go
MaxPerInstanceFailures
func (u *UpdateJob) MaxPerInstanceFailures(inst int32) *UpdateJob { u.req.Settings.MaxPerInstanceFailures = inst return u }
go
func (u *UpdateJob) MaxPerInstanceFailures(inst int32) *UpdateJob { u.req.Settings.MaxPerInstanceFailures = inst return u }
[ "func", "(", "u", "*", "UpdateJob", ")", "MaxPerInstanceFailures", "(", "inst", "int32", ")", "*", "UpdateJob", "{", "u", ".", "req", ".", "Settings", ".", "MaxPerInstanceFailures", "=", "inst", "\n", "return", "u", "\n", "}" ]
// Max number of instance failures to tolerate before marking instance as FAILED.
[ "Max", "number", "of", "instance", "failures", "to", "tolerate", "before", "marking", "instance", "as", "FAILED", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/updatejob.go#L134-L137
16,059
paypal/gorealis
updatejob.go
MaxFailedInstances
func (u *UpdateJob) MaxFailedInstances(inst int32) *UpdateJob { u.req.Settings.MaxFailedInstances = inst return u }
go
func (u *UpdateJob) MaxFailedInstances(inst int32) *UpdateJob { u.req.Settings.MaxFailedInstances = inst return u }
[ "func", "(", "u", "*", "UpdateJob", ")", "MaxFailedInstances", "(", "inst", "int32", ")", "*", "UpdateJob", "{", "u", ".", "req", ".", "Settings", ".", "MaxFailedInstances", "=", "inst", "\n", "return", "u", "\n", "}" ]
// Max number of FAILED instances to tolerate before terminating the update.
[ "Max", "number", "of", "FAILED", "instances", "to", "tolerate", "before", "terminating", "the", "update", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/updatejob.go#L140-L143
16,060
paypal/gorealis
updatejob.go
RollbackOnFail
func (u *UpdateJob) RollbackOnFail(rollback bool) *UpdateJob { u.req.Settings.RollbackOnFailure = rollback return u }
go
func (u *UpdateJob) RollbackOnFail(rollback bool) *UpdateJob { u.req.Settings.RollbackOnFailure = rollback return u }
[ "func", "(", "u", "*", "UpdateJob", ")", "RollbackOnFail", "(", "rollback", "bool", ")", "*", "UpdateJob", "{", "u", ".", "req", ".", "Settings", ".", "RollbackOnFailure", "=", "rollback", "\n", "return", "u", "\n", "}" ]
// When False, prevents auto rollback of a failed update.
[ "When", "False", "prevents", "auto", "rollback", "of", "a", "failed", "update", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/updatejob.go#L146-L149
16,061
paypal/gorealis
examples/jsonClient.go
init
func init() { flag.StringVar(&configJSONFile, "config", "./config.json", "The config file that contains username, password, and the cluster configuration information.") flag.StringVar(&jobJSONFile, "job", "./job.json", "JSON file containing job definitions.") flag.Parse() job = new(JobJson) config = new(Config) if jobsFile, jobJSONReadErr := os.Open(jobJSONFile); jobJSONReadErr != nil { flag.Usage() fmt.Println("Error reading the job JSON file: ", jobJSONReadErr) os.Exit(1) } else { if unmarshallErr := json.NewDecoder(jobsFile).Decode(job); unmarshallErr != nil { flag.Usage() fmt.Println("Error parsing job json file: ", unmarshallErr) os.Exit(1) } // Need to validate the job JSON file. if !job.Validate() { fmt.Println("Invalid Job.") os.Exit(1) } } if configFile, configJSONErr := os.Open(configJSONFile); configJSONErr != nil { flag.Usage() fmt.Println("Error reading the config JSON file: ", configJSONErr) os.Exit(1) } else { if unmarshallErr := json.NewDecoder(configFile).Decode(config); unmarshallErr != nil { fmt.Println("Error parsing config JSON file: ", unmarshallErr) os.Exit(1) } } }
go
func init() { flag.StringVar(&configJSONFile, "config", "./config.json", "The config file that contains username, password, and the cluster configuration information.") flag.StringVar(&jobJSONFile, "job", "./job.json", "JSON file containing job definitions.") flag.Parse() job = new(JobJson) config = new(Config) if jobsFile, jobJSONReadErr := os.Open(jobJSONFile); jobJSONReadErr != nil { flag.Usage() fmt.Println("Error reading the job JSON file: ", jobJSONReadErr) os.Exit(1) } else { if unmarshallErr := json.NewDecoder(jobsFile).Decode(job); unmarshallErr != nil { flag.Usage() fmt.Println("Error parsing job json file: ", unmarshallErr) os.Exit(1) } // Need to validate the job JSON file. if !job.Validate() { fmt.Println("Invalid Job.") os.Exit(1) } } if configFile, configJSONErr := os.Open(configJSONFile); configJSONErr != nil { flag.Usage() fmt.Println("Error reading the config JSON file: ", configJSONErr) os.Exit(1) } else { if unmarshallErr := json.NewDecoder(configFile).Decode(config); unmarshallErr != nil { fmt.Println("Error parsing config JSON file: ", unmarshallErr) os.Exit(1) } } }
[ "func", "init", "(", ")", "{", "flag", ".", "StringVar", "(", "&", "configJSONFile", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flag", ".", "StringVar", "(", "&", "jobJSONFile", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "flag", ".", "Parse", "(", ")", "\n\n", "job", "=", "new", "(", "JobJson", ")", "\n", "config", "=", "new", "(", "Config", ")", "\n\n", "if", "jobsFile", ",", "jobJSONReadErr", ":=", "os", ".", "Open", "(", "jobJSONFile", ")", ";", "jobJSONReadErr", "!=", "nil", "{", "flag", ".", "Usage", "(", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "jobJSONReadErr", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "else", "{", "if", "unmarshallErr", ":=", "json", ".", "NewDecoder", "(", "jobsFile", ")", ".", "Decode", "(", "job", ")", ";", "unmarshallErr", "!=", "nil", "{", "flag", ".", "Usage", "(", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "unmarshallErr", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n\n", "// Need to validate the job JSON file.", "if", "!", "job", ".", "Validate", "(", ")", "{", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n", "}", "\n\n", "if", "configFile", ",", "configJSONErr", ":=", "os", ".", "Open", "(", "configJSONFile", ")", ";", "configJSONErr", "!=", "nil", "{", "flag", ".", "Usage", "(", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "configJSONErr", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "else", "{", "if", "unmarshallErr", ":=", "json", ".", "NewDecoder", "(", "configFile", ")", ".", "Decode", "(", "config", ")", ";", "unmarshallErr", "!=", "nil", "{", "fmt", ".", "Println", "(", "\"", "\"", ",", "unmarshallErr", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Reading command line arguments and validating. // If Aurora scheduler URL not provided, then using zookeeper to locate the leader.
[ "Reading", "command", "line", "arguments", "and", "validating", ".", "If", "Aurora", "scheduler", "URL", "not", "provided", "then", "using", "zookeeper", "to", "locate", "the", "leader", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/examples/jsonClient.go#L89-L126
16,062
paypal/gorealis
realis.go
BasicAuth
func BasicAuth(username, password string) ClientOption { return func(config *RealisConfig) { config.username = username config.password = password } }
go
func BasicAuth(username, password string) ClientOption { return func(config *RealisConfig) { config.username = username config.password = password } }
[ "func", "BasicAuth", "(", "username", ",", "password", "string", ")", "ClientOption", "{", "return", "func", "(", "config", "*", "RealisConfig", ")", "{", "config", ".", "username", "=", "username", "\n", "config", ".", "password", "=", "password", "\n", "}", "\n", "}" ]
//Config sets for options in RealisConfig.
[ "Config", "sets", "for", "options", "in", "RealisConfig", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L131-L136
16,063
paypal/gorealis
realis.go
SetLogger
func SetLogger(l Logger) ClientOption { return func(config *RealisConfig) { config.logger = &LevelLogger{Logger: l} } }
go
func SetLogger(l Logger) ClientOption { return func(config *RealisConfig) { config.logger = &LevelLogger{Logger: l} } }
[ "func", "SetLogger", "(", "l", "Logger", ")", "ClientOption", "{", "return", "func", "(", "config", "*", "RealisConfig", ")", "{", "config", ".", "logger", "=", "&", "LevelLogger", "{", "Logger", ":", "l", "}", "\n", "}", "\n", "}" ]
// Using the word set to avoid name collision with Interface.
[ "Using", "the", "word", "set", "to", "avoid", "name", "collision", "with", "Interface", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L220-L224
16,064
paypal/gorealis
realis.go
defaultTTransport
func defaultTTransport(urlstr string, timeoutms int, config *RealisConfig) (thrift.TTransport, error) { jar, err := cookiejar.New(nil) if err != nil { return &thrift.THttpClient{}, errors.Wrap(err, "Error creating Cookie Jar") } var transport http.Transport if config != nil { tlsConfig := &tls.Config{} if config.InsecureSkipVerify { tlsConfig.InsecureSkipVerify = true } if config.certspath != "" { rootCAs, err := GetCerts(config.certspath) if err != nil { config.logger.Println("error occured couldn't fetch certs") return nil, err } tlsConfig.RootCAs = rootCAs } if config.clientkey != "" && config.clientcert == "" { return nil, fmt.Errorf("have to provide both client key,cert. Only client key provided ") } if config.clientkey == "" && config.clientcert != "" { return nil, fmt.Errorf("have to provide both client key,cert. Only client cert provided ") } if config.clientkey != "" && config.clientcert != "" { cert, err := tls.LoadX509KeyPair(config.clientcert, config.clientkey) if err != nil { config.logger.Println("error occured loading client certs and keys") return nil, err } tlsConfig.Certificates = []tls.Certificate{cert} } transport.TLSClientConfig = tlsConfig } trans, err := thrift.NewTHttpPostClientWithOptions(urlstr+"/api", thrift.THttpClientOptions{Client: &http.Client{Timeout: time.Millisecond * time.Duration(timeoutms), Transport: &transport, Jar: jar}}) if err != nil { return &thrift.THttpClient{}, errors.Wrap(err, "Error creating transport") } if err := trans.Open(); err != nil { return &thrift.THttpClient{}, errors.Wrapf(err, "Error opening connection to %s", urlstr) } return trans, nil }
go
func defaultTTransport(urlstr string, timeoutms int, config *RealisConfig) (thrift.TTransport, error) { jar, err := cookiejar.New(nil) if err != nil { return &thrift.THttpClient{}, errors.Wrap(err, "Error creating Cookie Jar") } var transport http.Transport if config != nil { tlsConfig := &tls.Config{} if config.InsecureSkipVerify { tlsConfig.InsecureSkipVerify = true } if config.certspath != "" { rootCAs, err := GetCerts(config.certspath) if err != nil { config.logger.Println("error occured couldn't fetch certs") return nil, err } tlsConfig.RootCAs = rootCAs } if config.clientkey != "" && config.clientcert == "" { return nil, fmt.Errorf("have to provide both client key,cert. Only client key provided ") } if config.clientkey == "" && config.clientcert != "" { return nil, fmt.Errorf("have to provide both client key,cert. Only client cert provided ") } if config.clientkey != "" && config.clientcert != "" { cert, err := tls.LoadX509KeyPair(config.clientcert, config.clientkey) if err != nil { config.logger.Println("error occured loading client certs and keys") return nil, err } tlsConfig.Certificates = []tls.Certificate{cert} } transport.TLSClientConfig = tlsConfig } trans, err := thrift.NewTHttpPostClientWithOptions(urlstr+"/api", thrift.THttpClientOptions{Client: &http.Client{Timeout: time.Millisecond * time.Duration(timeoutms), Transport: &transport, Jar: jar}}) if err != nil { return &thrift.THttpClient{}, errors.Wrap(err, "Error creating transport") } if err := trans.Open(); err != nil { return &thrift.THttpClient{}, errors.Wrapf(err, "Error opening connection to %s", urlstr) } return trans, nil }
[ "func", "defaultTTransport", "(", "urlstr", "string", ",", "timeoutms", "int", ",", "config", "*", "RealisConfig", ")", "(", "thrift", ".", "TTransport", ",", "error", ")", "{", "jar", ",", "err", ":=", "cookiejar", ".", "New", "(", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "&", "thrift", ".", "THttpClient", "{", "}", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "var", "transport", "http", ".", "Transport", "\n", "if", "config", "!=", "nil", "{", "tlsConfig", ":=", "&", "tls", ".", "Config", "{", "}", "\n", "if", "config", ".", "InsecureSkipVerify", "{", "tlsConfig", ".", "InsecureSkipVerify", "=", "true", "\n", "}", "\n", "if", "config", ".", "certspath", "!=", "\"", "\"", "{", "rootCAs", ",", "err", ":=", "GetCerts", "(", "config", ".", "certspath", ")", "\n", "if", "err", "!=", "nil", "{", "config", ".", "logger", ".", "Println", "(", "\"", "\"", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "tlsConfig", ".", "RootCAs", "=", "rootCAs", "\n", "}", "\n", "if", "config", ".", "clientkey", "!=", "\"", "\"", "&&", "config", ".", "clientcert", "==", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "config", ".", "clientkey", "==", "\"", "\"", "&&", "config", ".", "clientcert", "!=", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "config", ".", "clientkey", "!=", "\"", "\"", "&&", "config", ".", "clientcert", "!=", "\"", "\"", "{", "cert", ",", "err", ":=", "tls", ".", "LoadX509KeyPair", "(", "config", ".", "clientcert", ",", "config", ".", "clientkey", ")", "\n", "if", "err", "!=", "nil", "{", "config", ".", "logger", ".", "Println", "(", "\"", "\"", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "tlsConfig", ".", "Certificates", "=", "[", "]", "tls", ".", "Certificate", "{", "cert", "}", "\n", "}", "\n", "transport", ".", "TLSClientConfig", "=", "tlsConfig", "\n", "}", "\n\n", "trans", ",", "err", ":=", "thrift", ".", "NewTHttpPostClientWithOptions", "(", "urlstr", "+", "\"", "\"", ",", "thrift", ".", "THttpClientOptions", "{", "Client", ":", "&", "http", ".", "Client", "{", "Timeout", ":", "time", ".", "Millisecond", "*", "time", ".", "Duration", "(", "timeoutms", ")", ",", "Transport", ":", "&", "transport", ",", "Jar", ":", "jar", "}", "}", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "&", "thrift", ".", "THttpClient", "{", "}", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "err", ":=", "trans", ".", "Open", "(", ")", ";", "err", "!=", "nil", "{", "return", "&", "thrift", ".", "THttpClient", "{", "}", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "urlstr", ")", "\n", "}", "\n\n", "return", "trans", ",", "nil", "\n", "}" ]
// Creates a default Thrift Transport object for communications in gorealis using an HTTP Post Client
[ "Creates", "a", "default", "Thrift", "Transport", "object", "for", "communications", "in", "gorealis", "using", "an", "HTTP", "Post", "Client" ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L404-L452
16,065
paypal/gorealis
realis.go
newDefaultConfig
func newDefaultConfig(url string, timeoutms int, config *RealisConfig) (*RealisConfig, error) { return newTJSONConfig(url, timeoutms, config) }
go
func newDefaultConfig(url string, timeoutms int, config *RealisConfig) (*RealisConfig, error) { return newTJSONConfig(url, timeoutms, config) }
[ "func", "newDefaultConfig", "(", "url", "string", ",", "timeoutms", "int", ",", "config", "*", "RealisConfig", ")", "(", "*", "RealisConfig", ",", "error", ")", "{", "return", "newTJSONConfig", "(", "url", ",", "timeoutms", ",", "config", ")", "\n", "}" ]
// Create a default configuration of the transport layer, requires a URL to test connection with. // Uses HTTP Post as transport layer and Thrift JSON as the wire protocol by default.
[ "Create", "a", "default", "configuration", "of", "the", "transport", "layer", "requires", "a", "URL", "to", "test", "connection", "with", ".", "Uses", "HTTP", "Post", "as", "transport", "layer", "and", "Thrift", "JSON", "as", "the", "wire", "protocol", "by", "default", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L456-L458
16,066
paypal/gorealis
realis.go
newTJSONConfig
func newTJSONConfig(url string, timeoutms int, config *RealisConfig) (*RealisConfig, error) { trans, err := defaultTTransport(url, timeoutms, config) if err != nil { return &RealisConfig{}, errors.Wrap(err, "Error creating realis config") } httpTrans := (trans).(*thrift.THttpClient) httpTrans.SetHeader("Content-Type", "application/x-thrift") httpTrans.SetHeader("User-Agent", "gorealis v"+VERSION) return &RealisConfig{transport: trans, protoFactory: thrift.NewTJSONProtocolFactory()}, nil }
go
func newTJSONConfig(url string, timeoutms int, config *RealisConfig) (*RealisConfig, error) { trans, err := defaultTTransport(url, timeoutms, config) if err != nil { return &RealisConfig{}, errors.Wrap(err, "Error creating realis config") } httpTrans := (trans).(*thrift.THttpClient) httpTrans.SetHeader("Content-Type", "application/x-thrift") httpTrans.SetHeader("User-Agent", "gorealis v"+VERSION) return &RealisConfig{transport: trans, protoFactory: thrift.NewTJSONProtocolFactory()}, nil }
[ "func", "newTJSONConfig", "(", "url", "string", ",", "timeoutms", "int", ",", "config", "*", "RealisConfig", ")", "(", "*", "RealisConfig", ",", "error", ")", "{", "trans", ",", "err", ":=", "defaultTTransport", "(", "url", ",", "timeoutms", ",", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "&", "RealisConfig", "{", "}", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "httpTrans", ":=", "(", "trans", ")", ".", "(", "*", "thrift", ".", "THttpClient", ")", "\n", "httpTrans", ".", "SetHeader", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "httpTrans", ".", "SetHeader", "(", "\"", "\"", ",", "\"", "\"", "+", "VERSION", ")", "\n\n", "return", "&", "RealisConfig", "{", "transport", ":", "trans", ",", "protoFactory", ":", "thrift", ".", "NewTJSONProtocolFactory", "(", ")", "}", ",", "nil", "\n", "}" ]
// Creates a realis config object using HTTP Post and Thrift JSON protocol to communicate with Aurora.
[ "Creates", "a", "realis", "config", "object", "using", "HTTP", "Post", "and", "Thrift", "JSON", "protocol", "to", "communicate", "with", "Aurora", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L461-L472
16,067
paypal/gorealis
realis.go
Close
func (r *realisClient) Close() { r.lock.Lock() defer r.lock.Unlock() r.transport.Close() }
go
func (r *realisClient) Close() { r.lock.Lock() defer r.lock.Unlock() r.transport.Close() }
[ "func", "(", "r", "*", "realisClient", ")", "Close", "(", ")", "{", "r", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "r", ".", "transport", ".", "Close", "(", ")", "\n", "}" ]
// Releases resources associated with the realis client.
[ "Releases", "resources", "associated", "with", "the", "realis", "client", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L526-L532
16,068
paypal/gorealis
realis.go
GetInstanceIds
func (r *realisClient) GetInstanceIds(key *aurora.JobKey, states []aurora.ScheduleStatus) ([]int32, error) { taskQ := &aurora.TaskQuery{ Role: &key.Role, Environment: &key.Environment, JobName: &key.Name, Statuses: states, } r.logger.DebugPrintf("GetTasksWithoutConfigs Thrift Payload: %+v\n", taskQ) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.GetTasksWithoutConfigs(nil, taskQ) }) // If we encountered an error we couldn't recover from by retrying, return an error to the user if retryErr != nil { return nil, errors.Wrap(retryErr, "Error querying Aurora Scheduler for active IDs") } // Construct instance id map to stay in line with thrift's representation of sets tasks := response.ScheduleStatusResult(resp).GetTasks() jobInstanceIds := make([]int32, 0, len(tasks)) for _, task := range tasks { jobInstanceIds = append(jobInstanceIds, task.GetAssignedTask().GetInstanceId()) } return jobInstanceIds, nil }
go
func (r *realisClient) GetInstanceIds(key *aurora.JobKey, states []aurora.ScheduleStatus) ([]int32, error) { taskQ := &aurora.TaskQuery{ Role: &key.Role, Environment: &key.Environment, JobName: &key.Name, Statuses: states, } r.logger.DebugPrintf("GetTasksWithoutConfigs Thrift Payload: %+v\n", taskQ) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.GetTasksWithoutConfigs(nil, taskQ) }) // If we encountered an error we couldn't recover from by retrying, return an error to the user if retryErr != nil { return nil, errors.Wrap(retryErr, "Error querying Aurora Scheduler for active IDs") } // Construct instance id map to stay in line with thrift's representation of sets tasks := response.ScheduleStatusResult(resp).GetTasks() jobInstanceIds := make([]int32, 0, len(tasks)) for _, task := range tasks { jobInstanceIds = append(jobInstanceIds, task.GetAssignedTask().GetInstanceId()) } return jobInstanceIds, nil }
[ "func", "(", "r", "*", "realisClient", ")", "GetInstanceIds", "(", "key", "*", "aurora", ".", "JobKey", ",", "states", "[", "]", "aurora", ".", "ScheduleStatus", ")", "(", "[", "]", "int32", ",", "error", ")", "{", "taskQ", ":=", "&", "aurora", ".", "TaskQuery", "{", "Role", ":", "&", "key", ".", "Role", ",", "Environment", ":", "&", "key", ".", "Environment", ",", "JobName", ":", "&", "key", ".", "Name", ",", "Statuses", ":", "states", ",", "}", "\n\n", "r", ".", "logger", ".", "DebugPrintf", "(", "\"", "\\n", "\"", ",", "taskQ", ")", "\n\n", "resp", ",", "retryErr", ":=", "r", ".", "thriftCallWithRetries", "(", "func", "(", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "return", "r", ".", "client", ".", "GetTasksWithoutConfigs", "(", "nil", ",", "taskQ", ")", "\n", "}", ")", "\n\n", "// If we encountered an error we couldn't recover from by retrying, return an error to the user", "if", "retryErr", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "retryErr", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Construct instance id map to stay in line with thrift's representation of sets", "tasks", ":=", "response", ".", "ScheduleStatusResult", "(", "resp", ")", ".", "GetTasks", "(", ")", "\n", "jobInstanceIds", ":=", "make", "(", "[", "]", "int32", ",", "0", ",", "len", "(", "tasks", ")", ")", "\n", "for", "_", ",", "task", ":=", "range", "tasks", "{", "jobInstanceIds", "=", "append", "(", "jobInstanceIds", ",", "task", ".", "GetAssignedTask", "(", ")", ".", "GetInstanceId", "(", ")", ")", "\n", "}", "\n", "return", "jobInstanceIds", ",", "nil", "\n\n", "}" ]
// Uses predefined set of states to retrieve a set of active jobs in Apache Aurora.
[ "Uses", "predefined", "set", "of", "states", "to", "retrieve", "a", "set", "of", "active", "jobs", "in", "Apache", "Aurora", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L535-L562
16,069
paypal/gorealis
realis.go
CreateJob
func (r *realisClient) CreateJob(auroraJob Job) (*aurora.Response, error) { r.logger.DebugPrintf("CreateJob Thrift Payload: %+v\n", auroraJob.JobConfig()) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.CreateJob(nil, auroraJob.JobConfig()) }) if retryErr != nil { return resp, errors.Wrap(retryErr, "Error sending Create command to Aurora Scheduler") } return resp, nil }
go
func (r *realisClient) CreateJob(auroraJob Job) (*aurora.Response, error) { r.logger.DebugPrintf("CreateJob Thrift Payload: %+v\n", auroraJob.JobConfig()) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.CreateJob(nil, auroraJob.JobConfig()) }) if retryErr != nil { return resp, errors.Wrap(retryErr, "Error sending Create command to Aurora Scheduler") } return resp, nil }
[ "func", "(", "r", "*", "realisClient", ")", "CreateJob", "(", "auroraJob", "Job", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "r", ".", "logger", ".", "DebugPrintf", "(", "\"", "\\n", "\"", ",", "auroraJob", ".", "JobConfig", "(", ")", ")", "\n\n", "resp", ",", "retryErr", ":=", "r", ".", "thriftCallWithRetries", "(", "func", "(", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "return", "r", ".", "client", ".", "CreateJob", "(", "nil", ",", "auroraJob", ".", "JobConfig", "(", ")", ")", "\n", "}", ")", "\n\n", "if", "retryErr", "!=", "nil", "{", "return", "resp", ",", "errors", ".", "Wrap", "(", "retryErr", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "resp", ",", "nil", "\n", "}" ]
// Sends a create job message to the scheduler with a specific job configuration. // Although this API is able to create service jobs, it is better to use CreateService instead // as that API uses the update thrift call which has a few extra features available. // Use this API to create ad-hoc jobs.
[ "Sends", "a", "create", "job", "message", "to", "the", "scheduler", "with", "a", "specific", "job", "configuration", ".", "Although", "this", "API", "is", "able", "to", "create", "service", "jobs", "it", "is", "better", "to", "use", "CreateService", "instead", "as", "that", "API", "uses", "the", "update", "thrift", "call", "which", "has", "a", "few", "extra", "features", "available", ".", "Use", "this", "API", "to", "create", "ad", "-", "hoc", "jobs", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L636-L648
16,070
paypal/gorealis
realis.go
CreateService
func (r *realisClient) CreateService(auroraJob Job, settings *aurora.JobUpdateSettings) (*aurora.Response, *aurora.StartJobUpdateResult_, error) { // Create a new job update object and ship it to the StartJobUpdate api update := NewUpdateJob(auroraJob.TaskConfig(), settings) update.InstanceCount(auroraJob.GetInstanceCount()) resp, err := r.StartJobUpdate(update, "") if err != nil { return resp, nil, errors.Wrap(err, "unable to create service") } if resp.GetResult_() != nil { return resp, resp.GetResult_().GetStartJobUpdateResult_(), nil } return nil, nil, errors.New("results object is nil") }
go
func (r *realisClient) CreateService(auroraJob Job, settings *aurora.JobUpdateSettings) (*aurora.Response, *aurora.StartJobUpdateResult_, error) { // Create a new job update object and ship it to the StartJobUpdate api update := NewUpdateJob(auroraJob.TaskConfig(), settings) update.InstanceCount(auroraJob.GetInstanceCount()) resp, err := r.StartJobUpdate(update, "") if err != nil { return resp, nil, errors.Wrap(err, "unable to create service") } if resp.GetResult_() != nil { return resp, resp.GetResult_().GetStartJobUpdateResult_(), nil } return nil, nil, errors.New("results object is nil") }
[ "func", "(", "r", "*", "realisClient", ")", "CreateService", "(", "auroraJob", "Job", ",", "settings", "*", "aurora", ".", "JobUpdateSettings", ")", "(", "*", "aurora", ".", "Response", ",", "*", "aurora", ".", "StartJobUpdateResult_", ",", "error", ")", "{", "// Create a new job update object and ship it to the StartJobUpdate api", "update", ":=", "NewUpdateJob", "(", "auroraJob", ".", "TaskConfig", "(", ")", ",", "settings", ")", "\n", "update", ".", "InstanceCount", "(", "auroraJob", ".", "GetInstanceCount", "(", ")", ")", "\n\n", "resp", ",", "err", ":=", "r", ".", "StartJobUpdate", "(", "update", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "resp", ",", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "resp", ".", "GetResult_", "(", ")", "!=", "nil", "{", "return", "resp", ",", "resp", ".", "GetResult_", "(", ")", ".", "GetStartJobUpdateResult_", "(", ")", ",", "nil", "\n", "}", "\n\n", "return", "nil", ",", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}" ]
// This API uses an update thrift call to create the services giving a few more robust features.
[ "This", "API", "uses", "an", "update", "thrift", "call", "to", "create", "the", "services", "giving", "a", "few", "more", "robust", "features", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L651-L666
16,071
paypal/gorealis
realis.go
RestartInstances
func (r *realisClient) RestartInstances(key *aurora.JobKey, instances ...int32) (*aurora.Response, error) { r.logger.DebugPrintf("RestartShards Thrift Payload: %+v %v\n", key, instances) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.RestartShards(nil, key, instances) }) if retryErr != nil { return nil, errors.Wrap(retryErr, "Error sending Restart command to Aurora Scheduler") } return resp, nil }
go
func (r *realisClient) RestartInstances(key *aurora.JobKey, instances ...int32) (*aurora.Response, error) { r.logger.DebugPrintf("RestartShards Thrift Payload: %+v %v\n", key, instances) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.RestartShards(nil, key, instances) }) if retryErr != nil { return nil, errors.Wrap(retryErr, "Error sending Restart command to Aurora Scheduler") } return resp, nil }
[ "func", "(", "r", "*", "realisClient", ")", "RestartInstances", "(", "key", "*", "aurora", ".", "JobKey", ",", "instances", "...", "int32", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "r", ".", "logger", ".", "DebugPrintf", "(", "\"", "\\n", "\"", ",", "key", ",", "instances", ")", "\n\n", "resp", ",", "retryErr", ":=", "r", ".", "thriftCallWithRetries", "(", "func", "(", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "return", "r", ".", "client", ".", "RestartShards", "(", "nil", ",", "key", ",", "instances", ")", "\n", "}", ")", "\n\n", "if", "retryErr", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "retryErr", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "resp", ",", "nil", "\n", "}" ]
// Restarts specific instances specified
[ "Restarts", "specific", "instances", "specified" ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L713-L724
16,072
paypal/gorealis
realis.go
RestartJob
func (r *realisClient) RestartJob(key *aurora.JobKey) (*aurora.Response, error) { instanceIds, err1 := r.GetInstanceIds(key, aurora.ACTIVE_STATES) if err1 != nil { return nil, errors.Wrap(err1, "Could not retrieve relevant task instance IDs") } r.logger.DebugPrintf("RestartShards Thrift Payload: %+v %v\n", key, instanceIds) if len(instanceIds) > 0 { resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.RestartShards(nil, key, instanceIds) }) if retryErr != nil { return nil, errors.Wrap(retryErr, "Error sending Restart command to Aurora Scheduler") } return resp, nil } else { return nil, errors.New("No tasks in the Active state") } }
go
func (r *realisClient) RestartJob(key *aurora.JobKey) (*aurora.Response, error) { instanceIds, err1 := r.GetInstanceIds(key, aurora.ACTIVE_STATES) if err1 != nil { return nil, errors.Wrap(err1, "Could not retrieve relevant task instance IDs") } r.logger.DebugPrintf("RestartShards Thrift Payload: %+v %v\n", key, instanceIds) if len(instanceIds) > 0 { resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.RestartShards(nil, key, instanceIds) }) if retryErr != nil { return nil, errors.Wrap(retryErr, "Error sending Restart command to Aurora Scheduler") } return resp, nil } else { return nil, errors.New("No tasks in the Active state") } }
[ "func", "(", "r", "*", "realisClient", ")", "RestartJob", "(", "key", "*", "aurora", ".", "JobKey", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "instanceIds", ",", "err1", ":=", "r", ".", "GetInstanceIds", "(", "key", ",", "aurora", ".", "ACTIVE_STATES", ")", "\n", "if", "err1", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err1", ",", "\"", "\"", ")", "\n", "}", "\n\n", "r", ".", "logger", ".", "DebugPrintf", "(", "\"", "\\n", "\"", ",", "key", ",", "instanceIds", ")", "\n\n", "if", "len", "(", "instanceIds", ")", ">", "0", "{", "resp", ",", "retryErr", ":=", "r", ".", "thriftCallWithRetries", "(", "func", "(", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "return", "r", ".", "client", ".", "RestartShards", "(", "nil", ",", "key", ",", "instanceIds", ")", "\n", "}", ")", "\n\n", "if", "retryErr", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "retryErr", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "resp", ",", "nil", "\n", "}", "else", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// Restarts all active tasks under a job configuration.
[ "Restarts", "all", "active", "tasks", "under", "a", "job", "configuration", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L727-L749
16,073
paypal/gorealis
realis.go
StartJobUpdate
func (r *realisClient) StartJobUpdate(updateJob *UpdateJob, message string) (*aurora.Response, error) { r.logger.DebugPrintf("StartJobUpdate Thrift Payload: %+v %v\n", updateJob, message) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.StartJobUpdate(nil, updateJob.req, message) }) if retryErr != nil { return resp, errors.Wrap(retryErr, "Error sending StartJobUpdate command to Aurora Scheduler") } return resp, nil }
go
func (r *realisClient) StartJobUpdate(updateJob *UpdateJob, message string) (*aurora.Response, error) { r.logger.DebugPrintf("StartJobUpdate Thrift Payload: %+v %v\n", updateJob, message) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.StartJobUpdate(nil, updateJob.req, message) }) if retryErr != nil { return resp, errors.Wrap(retryErr, "Error sending StartJobUpdate command to Aurora Scheduler") } return resp, nil }
[ "func", "(", "r", "*", "realisClient", ")", "StartJobUpdate", "(", "updateJob", "*", "UpdateJob", ",", "message", "string", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "r", ".", "logger", ".", "DebugPrintf", "(", "\"", "\\n", "\"", ",", "updateJob", ",", "message", ")", "\n\n", "resp", ",", "retryErr", ":=", "r", ".", "thriftCallWithRetries", "(", "func", "(", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "return", "r", ".", "client", ".", "StartJobUpdate", "(", "nil", ",", "updateJob", ".", "req", ",", "message", ")", "\n", "}", ")", "\n\n", "if", "retryErr", "!=", "nil", "{", "return", "resp", ",", "errors", ".", "Wrap", "(", "retryErr", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "resp", ",", "nil", "\n", "}" ]
// Update all tasks under a job configuration. Currently gorealis doesn't support for canary deployments.
[ "Update", "all", "tasks", "under", "a", "job", "configuration", ".", "Currently", "gorealis", "doesn", "t", "support", "for", "canary", "deployments", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L752-L764
16,074
paypal/gorealis
realis.go
AbortJobUpdate
func (r *realisClient) AbortJobUpdate(updateKey aurora.JobUpdateKey, message string) (*aurora.Response, error) { r.logger.DebugPrintf("AbortJobUpdate Thrift Payload: %+v %v\n", updateKey, message) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.AbortJobUpdate(nil, &updateKey, message) }) if retryErr != nil { return nil, errors.Wrap(retryErr, "Error sending AbortJobUpdate command to Aurora Scheduler") } // Make this call synchronous by blocking until it job has successfully transitioned to aborted m := Monitor{Client: r} _, err := m.JobUpdateStatus(updateKey, map[aurora.JobUpdateStatus]bool{aurora.JobUpdateStatus_ABORTED: true}, time.Second*5, time.Minute) return resp, err }
go
func (r *realisClient) AbortJobUpdate(updateKey aurora.JobUpdateKey, message string) (*aurora.Response, error) { r.logger.DebugPrintf("AbortJobUpdate Thrift Payload: %+v %v\n", updateKey, message) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.AbortJobUpdate(nil, &updateKey, message) }) if retryErr != nil { return nil, errors.Wrap(retryErr, "Error sending AbortJobUpdate command to Aurora Scheduler") } // Make this call synchronous by blocking until it job has successfully transitioned to aborted m := Monitor{Client: r} _, err := m.JobUpdateStatus(updateKey, map[aurora.JobUpdateStatus]bool{aurora.JobUpdateStatus_ABORTED: true}, time.Second*5, time.Minute) return resp, err }
[ "func", "(", "r", "*", "realisClient", ")", "AbortJobUpdate", "(", "updateKey", "aurora", ".", "JobUpdateKey", ",", "message", "string", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "r", ".", "logger", ".", "DebugPrintf", "(", "\"", "\\n", "\"", ",", "updateKey", ",", "message", ")", "\n\n", "resp", ",", "retryErr", ":=", "r", ".", "thriftCallWithRetries", "(", "func", "(", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "return", "r", ".", "client", ".", "AbortJobUpdate", "(", "nil", ",", "&", "updateKey", ",", "message", ")", "\n", "}", ")", "\n\n", "if", "retryErr", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "retryErr", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Make this call synchronous by blocking until it job has successfully transitioned to aborted", "m", ":=", "Monitor", "{", "Client", ":", "r", "}", "\n", "_", ",", "err", ":=", "m", ".", "JobUpdateStatus", "(", "updateKey", ",", "map", "[", "aurora", ".", "JobUpdateStatus", "]", "bool", "{", "aurora", ".", "JobUpdateStatus_ABORTED", ":", "true", "}", ",", "time", ".", "Second", "*", "5", ",", "time", ".", "Minute", ")", "\n\n", "return", "resp", ",", "err", "\n", "}" ]
// Abort Job Update on Aurora. Requires the updateId which can be obtained on the Aurora web UI. // This API is meant to be synchronous. It will attempt to wait until the update transitions to the aborted state. // However, if the job update does not transition to the ABORT state an error will be returned.
[ "Abort", "Job", "Update", "on", "Aurora", ".", "Requires", "the", "updateId", "which", "can", "be", "obtained", "on", "the", "Aurora", "web", "UI", ".", "This", "API", "is", "meant", "to", "be", "synchronous", ".", "It", "will", "attempt", "to", "wait", "until", "the", "update", "transitions", "to", "the", "aborted", "state", ".", "However", "if", "the", "job", "update", "does", "not", "transition", "to", "the", "ABORT", "state", "an", "error", "will", "be", "returned", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L769-L786
16,075
paypal/gorealis
realis.go
ResumeJobUpdate
func (r *realisClient) ResumeJobUpdate(updateKey *aurora.JobUpdateKey, message string) (*aurora.Response, error) { r.logger.DebugPrintf("ResumeJobUpdate Thrift Payload: %+v %v\n", updateKey, message) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.ResumeJobUpdate(nil, updateKey, message) }) if retryErr != nil { return nil, errors.Wrap(retryErr, "Error sending ResumeJobUpdate command to Aurora Scheduler") } return resp, nil }
go
func (r *realisClient) ResumeJobUpdate(updateKey *aurora.JobUpdateKey, message string) (*aurora.Response, error) { r.logger.DebugPrintf("ResumeJobUpdate Thrift Payload: %+v %v\n", updateKey, message) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.ResumeJobUpdate(nil, updateKey, message) }) if retryErr != nil { return nil, errors.Wrap(retryErr, "Error sending ResumeJobUpdate command to Aurora Scheduler") } return resp, nil }
[ "func", "(", "r", "*", "realisClient", ")", "ResumeJobUpdate", "(", "updateKey", "*", "aurora", ".", "JobUpdateKey", ",", "message", "string", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "r", ".", "logger", ".", "DebugPrintf", "(", "\"", "\\n", "\"", ",", "updateKey", ",", "message", ")", "\n\n", "resp", ",", "retryErr", ":=", "r", ".", "thriftCallWithRetries", "(", "func", "(", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "return", "r", ".", "client", ".", "ResumeJobUpdate", "(", "nil", ",", "updateKey", ",", "message", ")", "\n", "}", ")", "\n\n", "if", "retryErr", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "retryErr", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "resp", ",", "nil", "\n", "}" ]
//Resume Paused Job Update. UpdateID is returned from StartJobUpdate or the Aurora web UI.
[ "Resume", "Paused", "Job", "Update", ".", "UpdateID", "is", "returned", "from", "StartJobUpdate", "or", "the", "Aurora", "web", "UI", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L805-L818
16,076
paypal/gorealis
realis.go
AddInstances
func (r *realisClient) AddInstances(instKey aurora.InstanceKey, count int32) (*aurora.Response, error) { r.logger.DebugPrintf("AddInstances Thrift Payload: %+v %v\n", instKey, count) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.AddInstances(nil, &instKey, count) }) if retryErr != nil { return nil, errors.Wrap(retryErr, "Error sending AddInstances command to Aurora Scheduler") } return resp, nil }
go
func (r *realisClient) AddInstances(instKey aurora.InstanceKey, count int32) (*aurora.Response, error) { r.logger.DebugPrintf("AddInstances Thrift Payload: %+v %v\n", instKey, count) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.AddInstances(nil, &instKey, count) }) if retryErr != nil { return nil, errors.Wrap(retryErr, "Error sending AddInstances command to Aurora Scheduler") } return resp, nil }
[ "func", "(", "r", "*", "realisClient", ")", "AddInstances", "(", "instKey", "aurora", ".", "InstanceKey", ",", "count", "int32", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "r", ".", "logger", ".", "DebugPrintf", "(", "\"", "\\n", "\"", ",", "instKey", ",", "count", ")", "\n\n", "resp", ",", "retryErr", ":=", "r", ".", "thriftCallWithRetries", "(", "func", "(", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "return", "r", ".", "client", ".", "AddInstances", "(", "nil", ",", "&", "instKey", ",", "count", ")", "\n", "}", ")", "\n\n", "if", "retryErr", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "retryErr", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "resp", ",", "nil", "\n\n", "}" ]
// Scale up the number of instances under a job configuration using the configuration for specific // instance to scale up.
[ "Scale", "up", "the", "number", "of", "instances", "under", "a", "job", "configuration", "using", "the", "configuration", "for", "specific", "instance", "to", "scale", "up", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L838-L851
16,077
paypal/gorealis
realis.go
RemoveInstances
func (r *realisClient) RemoveInstances(key *aurora.JobKey, count int32) (*aurora.Response, error) { instanceIds, err := r.GetInstanceIds(key, aurora.ACTIVE_STATES) if err != nil { return nil, errors.Wrap(err, "RemoveInstances: Could not retrieve relevant instance IDs") } if len(instanceIds) < int(count) { return nil, errors.Errorf("Insufficient active instances available for killing: "+ " Instances to be killed %d Active instances %d", count, len(instanceIds)) } // Sort instanceIds in ** decreasing ** order sort.Slice(instanceIds, func(i, j int) bool { return instanceIds[i] > instanceIds[j] }) // Kill the instances with the highest ID number first return r.KillInstances(key, instanceIds[:count]...) }
go
func (r *realisClient) RemoveInstances(key *aurora.JobKey, count int32) (*aurora.Response, error) { instanceIds, err := r.GetInstanceIds(key, aurora.ACTIVE_STATES) if err != nil { return nil, errors.Wrap(err, "RemoveInstances: Could not retrieve relevant instance IDs") } if len(instanceIds) < int(count) { return nil, errors.Errorf("Insufficient active instances available for killing: "+ " Instances to be killed %d Active instances %d", count, len(instanceIds)) } // Sort instanceIds in ** decreasing ** order sort.Slice(instanceIds, func(i, j int) bool { return instanceIds[i] > instanceIds[j] }) // Kill the instances with the highest ID number first return r.KillInstances(key, instanceIds[:count]...) }
[ "func", "(", "r", "*", "realisClient", ")", "RemoveInstances", "(", "key", "*", "aurora", ".", "JobKey", ",", "count", "int32", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "instanceIds", ",", "err", ":=", "r", ".", "GetInstanceIds", "(", "key", ",", "aurora", ".", "ACTIVE_STATES", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "instanceIds", ")", "<", "int", "(", "count", ")", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", "+", "\"", "\"", ",", "count", ",", "len", "(", "instanceIds", ")", ")", "\n", "}", "\n\n", "// Sort instanceIds in ** decreasing ** order", "sort", ".", "Slice", "(", "instanceIds", ",", "func", "(", "i", ",", "j", "int", ")", "bool", "{", "return", "instanceIds", "[", "i", "]", ">", "instanceIds", "[", "j", "]", "\n", "}", ")", "\n\n", "// Kill the instances with the highest ID number first", "return", "r", ".", "KillInstances", "(", "key", ",", "instanceIds", "[", ":", "count", "]", "...", ")", "\n", "}" ]
// Scale down the number of instances under a job configuration using the configuration of a specific instance
[ "Scale", "down", "the", "number", "of", "instances", "under", "a", "job", "configuration", "using", "the", "configuration", "of", "a", "specific", "instance" ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L854-L872
16,078
paypal/gorealis
realis.go
GetTaskStatus
func (r *realisClient) GetTaskStatus(query *aurora.TaskQuery) ([]*aurora.ScheduledTask, error) { r.logger.DebugPrintf("GetTasksStatus Thrift Payload: %+v\n", query) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.GetTasksStatus(nil, query) }) if retryErr != nil { return nil, errors.Wrap(retryErr, "Error querying Aurora Scheduler for task status") } return response.ScheduleStatusResult(resp).GetTasks(), nil }
go
func (r *realisClient) GetTaskStatus(query *aurora.TaskQuery) ([]*aurora.ScheduledTask, error) { r.logger.DebugPrintf("GetTasksStatus Thrift Payload: %+v\n", query) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.GetTasksStatus(nil, query) }) if retryErr != nil { return nil, errors.Wrap(retryErr, "Error querying Aurora Scheduler for task status") } return response.ScheduleStatusResult(resp).GetTasks(), nil }
[ "func", "(", "r", "*", "realisClient", ")", "GetTaskStatus", "(", "query", "*", "aurora", ".", "TaskQuery", ")", "(", "[", "]", "*", "aurora", ".", "ScheduledTask", ",", "error", ")", "{", "r", ".", "logger", ".", "DebugPrintf", "(", "\"", "\\n", "\"", ",", "query", ")", "\n\n", "resp", ",", "retryErr", ":=", "r", ".", "thriftCallWithRetries", "(", "func", "(", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "return", "r", ".", "client", ".", "GetTasksStatus", "(", "nil", ",", "query", ")", "\n", "}", ")", "\n\n", "if", "retryErr", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "retryErr", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "response", ".", "ScheduleStatusResult", "(", "resp", ")", ".", "GetTasks", "(", ")", ",", "nil", "\n", "}" ]
// Get information about task including a fully hydrated task configuration object
[ "Get", "information", "about", "task", "including", "a", "fully", "hydrated", "task", "configuration", "object" ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L875-L888
16,079
paypal/gorealis
realis.go
GetPendingReason
func (r *realisClient) GetPendingReason(query *aurora.TaskQuery) ([]*aurora.PendingReason, error) { r.logger.DebugPrintf("GetPendingReason Thrift Payload: %+v\n", query) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.GetPendingReason(nil, query) }) if retryErr != nil { return nil, errors.Wrap(retryErr, "Error querying Aurora Scheduler for pending Reasons") } var pendingReasons []*aurora.PendingReason if resp.GetResult_() != nil { pendingReasons = resp.GetResult_().GetGetPendingReasonResult_().GetReasons() } return pendingReasons, nil }
go
func (r *realisClient) GetPendingReason(query *aurora.TaskQuery) ([]*aurora.PendingReason, error) { r.logger.DebugPrintf("GetPendingReason Thrift Payload: %+v\n", query) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.GetPendingReason(nil, query) }) if retryErr != nil { return nil, errors.Wrap(retryErr, "Error querying Aurora Scheduler for pending Reasons") } var pendingReasons []*aurora.PendingReason if resp.GetResult_() != nil { pendingReasons = resp.GetResult_().GetGetPendingReasonResult_().GetReasons() } return pendingReasons, nil }
[ "func", "(", "r", "*", "realisClient", ")", "GetPendingReason", "(", "query", "*", "aurora", ".", "TaskQuery", ")", "(", "[", "]", "*", "aurora", ".", "PendingReason", ",", "error", ")", "{", "r", ".", "logger", ".", "DebugPrintf", "(", "\"", "\\n", "\"", ",", "query", ")", "\n\n", "resp", ",", "retryErr", ":=", "r", ".", "thriftCallWithRetries", "(", "func", "(", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "return", "r", ".", "client", ".", "GetPendingReason", "(", "nil", ",", "query", ")", "\n", "}", ")", "\n\n", "if", "retryErr", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "retryErr", ",", "\"", "\"", ")", "\n", "}", "\n\n", "var", "pendingReasons", "[", "]", "*", "aurora", ".", "PendingReason", "\n\n", "if", "resp", ".", "GetResult_", "(", ")", "!=", "nil", "{", "pendingReasons", "=", "resp", ".", "GetResult_", "(", ")", ".", "GetGetPendingReasonResult_", "(", ")", ".", "GetReasons", "(", ")", "\n", "}", "\n\n", "return", "pendingReasons", ",", "nil", "\n", "}" ]
// Get pending reason
[ "Get", "pending", "reason" ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L891-L910
16,080
paypal/gorealis
realis.go
FetchTaskConfig
func (r *realisClient) FetchTaskConfig(instKey aurora.InstanceKey) (*aurora.TaskConfig, error) { taskQ := &aurora.TaskQuery{ Role: &instKey.JobKey.Role, Environment: &instKey.JobKey.Environment, JobName: &instKey.JobKey.Name, InstanceIds: []int32{instKey.InstanceId}, Statuses: aurora.ACTIVE_STATES, } r.logger.DebugPrintf("GetTasksStatus Thrift Payload: %+v\n", taskQ) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.GetTasksStatus(nil, taskQ) }) if retryErr != nil { return nil, errors.Wrap(retryErr, "Error querying Aurora Scheduler for task configuration") } tasks := response.ScheduleStatusResult(resp).GetTasks() if len(tasks) == 0 { return nil, errors.Errorf("Instance %d for jobkey %s/%s/%s doesn't exist", instKey.InstanceId, instKey.JobKey.Environment, instKey.JobKey.Role, instKey.JobKey.Name) } // Currently, instance 0 is always picked.. return tasks[0].AssignedTask.Task, nil }
go
func (r *realisClient) FetchTaskConfig(instKey aurora.InstanceKey) (*aurora.TaskConfig, error) { taskQ := &aurora.TaskQuery{ Role: &instKey.JobKey.Role, Environment: &instKey.JobKey.Environment, JobName: &instKey.JobKey.Name, InstanceIds: []int32{instKey.InstanceId}, Statuses: aurora.ACTIVE_STATES, } r.logger.DebugPrintf("GetTasksStatus Thrift Payload: %+v\n", taskQ) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.client.GetTasksStatus(nil, taskQ) }) if retryErr != nil { return nil, errors.Wrap(retryErr, "Error querying Aurora Scheduler for task configuration") } tasks := response.ScheduleStatusResult(resp).GetTasks() if len(tasks) == 0 { return nil, errors.Errorf("Instance %d for jobkey %s/%s/%s doesn't exist", instKey.InstanceId, instKey.JobKey.Environment, instKey.JobKey.Role, instKey.JobKey.Name) } // Currently, instance 0 is always picked.. return tasks[0].AssignedTask.Task, nil }
[ "func", "(", "r", "*", "realisClient", ")", "FetchTaskConfig", "(", "instKey", "aurora", ".", "InstanceKey", ")", "(", "*", "aurora", ".", "TaskConfig", ",", "error", ")", "{", "taskQ", ":=", "&", "aurora", ".", "TaskQuery", "{", "Role", ":", "&", "instKey", ".", "JobKey", ".", "Role", ",", "Environment", ":", "&", "instKey", ".", "JobKey", ".", "Environment", ",", "JobName", ":", "&", "instKey", ".", "JobKey", ".", "Name", ",", "InstanceIds", ":", "[", "]", "int32", "{", "instKey", ".", "InstanceId", "}", ",", "Statuses", ":", "aurora", ".", "ACTIVE_STATES", ",", "}", "\n\n", "r", ".", "logger", ".", "DebugPrintf", "(", "\"", "\\n", "\"", ",", "taskQ", ")", "\n\n", "resp", ",", "retryErr", ":=", "r", ".", "thriftCallWithRetries", "(", "func", "(", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "return", "r", ".", "client", ".", "GetTasksStatus", "(", "nil", ",", "taskQ", ")", "\n", "}", ")", "\n\n", "if", "retryErr", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "retryErr", ",", "\"", "\"", ")", "\n", "}", "\n\n", "tasks", ":=", "response", ".", "ScheduleStatusResult", "(", "resp", ")", ".", "GetTasks", "(", ")", "\n\n", "if", "len", "(", "tasks", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "instKey", ".", "InstanceId", ",", "instKey", ".", "JobKey", ".", "Environment", ",", "instKey", ".", "JobKey", ".", "Role", ",", "instKey", ".", "JobKey", ".", "Name", ")", "\n", "}", "\n\n", "// Currently, instance 0 is always picked..", "return", "tasks", "[", "0", "]", ".", "AssignedTask", ".", "Task", ",", "nil", "\n", "}" ]
// Get the task configuration from the aurora scheduler for a job
[ "Get", "the", "task", "configuration", "from", "the", "aurora", "scheduler", "for", "a", "job" ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L930-L961
16,081
paypal/gorealis
realis.go
SLADrainHosts
func (r *realisClient) SLADrainHosts(policy *aurora.SlaPolicy, timeout int64, hosts ...string) (*aurora.DrainHostsResult_, error) { var result *aurora.DrainHostsResult_ if len(hosts) == 0 { return nil, errors.New("no hosts provided to drain") } drainList := aurora.NewHosts() drainList.HostNames = hosts r.logger.DebugPrintf("SLADrainHosts Thrift Payload: %v\n", drainList) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.adminClient.SlaDrainHosts(nil, drainList, policy, timeout) }) if retryErr != nil { return result, errors.Wrap(retryErr, "Unable to recover connection") } if resp.GetResult_() != nil { result = resp.GetResult_().GetDrainHostsResult_() } return result, nil }
go
func (r *realisClient) SLADrainHosts(policy *aurora.SlaPolicy, timeout int64, hosts ...string) (*aurora.DrainHostsResult_, error) { var result *aurora.DrainHostsResult_ if len(hosts) == 0 { return nil, errors.New("no hosts provided to drain") } drainList := aurora.NewHosts() drainList.HostNames = hosts r.logger.DebugPrintf("SLADrainHosts Thrift Payload: %v\n", drainList) resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.adminClient.SlaDrainHosts(nil, drainList, policy, timeout) }) if retryErr != nil { return result, errors.Wrap(retryErr, "Unable to recover connection") } if resp.GetResult_() != nil { result = resp.GetResult_().GetDrainHostsResult_() } return result, nil }
[ "func", "(", "r", "*", "realisClient", ")", "SLADrainHosts", "(", "policy", "*", "aurora", ".", "SlaPolicy", ",", "timeout", "int64", ",", "hosts", "...", "string", ")", "(", "*", "aurora", ".", "DrainHostsResult_", ",", "error", ")", "{", "var", "result", "*", "aurora", ".", "DrainHostsResult_", "\n\n", "if", "len", "(", "hosts", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "drainList", ":=", "aurora", ".", "NewHosts", "(", ")", "\n", "drainList", ".", "HostNames", "=", "hosts", "\n\n", "r", ".", "logger", ".", "DebugPrintf", "(", "\"", "\\n", "\"", ",", "drainList", ")", "\n\n", "resp", ",", "retryErr", ":=", "r", ".", "thriftCallWithRetries", "(", "func", "(", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "return", "r", ".", "adminClient", ".", "SlaDrainHosts", "(", "nil", ",", "drainList", ",", "policy", ",", "timeout", ")", "\n", "}", ")", "\n\n", "if", "retryErr", "!=", "nil", "{", "return", "result", ",", "errors", ".", "Wrap", "(", "retryErr", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "resp", ".", "GetResult_", "(", ")", "!=", "nil", "{", "result", "=", "resp", ".", "GetResult_", "(", ")", ".", "GetDrainHostsResult_", "(", ")", "\n", "}", "\n\n", "return", "result", ",", "nil", "\n", "}" ]
// Start SLA Aware Drain. // defaultSlaPolicy is the fallback SlaPolicy to use if a task does not have an SlaPolicy. // After timeoutSecs, tasks will be forcefully drained without checking SLA.
[ "Start", "SLA", "Aware", "Drain", ".", "defaultSlaPolicy", "is", "the", "fallback", "SlaPolicy", "to", "use", "if", "a", "task", "does", "not", "have", "an", "SlaPolicy", ".", "After", "timeoutSecs", "tasks", "will", "be", "forcefully", "drained", "without", "checking", "SLA", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L1030-L1055
16,082
paypal/gorealis
realis.go
GetQuota
func (r *realisClient) GetQuota(role string) (*aurora.Response, error) { resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.adminClient.GetQuota(nil, role) }) if retryErr != nil { return resp, errors.Wrap(retryErr, "Unable to get role quota") } return resp, retryErr }
go
func (r *realisClient) GetQuota(role string) (*aurora.Response, error) { resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { return r.adminClient.GetQuota(nil, role) }) if retryErr != nil { return resp, errors.Wrap(retryErr, "Unable to get role quota") } return resp, retryErr }
[ "func", "(", "r", "*", "realisClient", ")", "GetQuota", "(", "role", "string", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "resp", ",", "retryErr", ":=", "r", ".", "thriftCallWithRetries", "(", "func", "(", ")", "(", "*", "aurora", ".", "Response", ",", "error", ")", "{", "return", "r", ".", "adminClient", ".", "GetQuota", "(", "nil", ",", "role", ")", "\n", "}", ")", "\n\n", "if", "retryErr", "!=", "nil", "{", "return", "resp", ",", "errors", ".", "Wrap", "(", "retryErr", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "resp", ",", "retryErr", "\n", "}" ]
// GetQuota returns the resource aggregate for the given role
[ "GetQuota", "returns", "the", "resource", "aggregate", "for", "the", "given", "role" ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/realis.go#L1166-L1176
16,083
paypal/gorealis
errors.go
ToRetryCount
func ToRetryCount(err error) *retryErr { if retryErr, ok := err.(*retryErr); ok { return retryErr } else { return nil } }
go
func ToRetryCount(err error) *retryErr { if retryErr, ok := err.(*retryErr); ok { return retryErr } else { return nil } }
[ "func", "ToRetryCount", "(", "err", "error", ")", "*", "retryErr", "{", "if", "retryErr", ",", "ok", ":=", "err", ".", "(", "*", "retryErr", ")", ";", "ok", "{", "return", "retryErr", "\n", "}", "else", "{", "return", "nil", "\n", "}", "\n", "}" ]
// Helper function for testing verification to avoid whitebox testing // as well as keeping retryErr as a private. // Should NOT be used under any other context.
[ "Helper", "function", "for", "testing", "verification", "to", "avoid", "whitebox", "testing", "as", "well", "as", "keeping", "retryErr", "as", "a", "private", ".", "Should", "NOT", "be", "used", "under", "any", "other", "context", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/errors.go#L67-L73
16,084
paypal/gorealis
job.go
NewJob
func NewJob() Job { jobConfig := aurora.NewJobConfiguration() taskConfig := aurora.NewTaskConfig() jobKey := aurora.NewJobKey() // Job Config jobConfig.Key = jobKey jobConfig.TaskConfig = taskConfig // Task Config taskConfig.Job = jobKey taskConfig.Container = aurora.NewContainer() taskConfig.Container.Mesos = aurora.NewMesosContainer() // Resources numCpus := aurora.NewResource() ramMb := aurora.NewResource() diskMb := aurora.NewResource() resources := map[ResourceType]*aurora.Resource{CPU: numCpus, RAM: ramMb, DISK: diskMb} taskConfig.Resources = []*aurora.Resource{numCpus, ramMb, diskMb} numCpus.NumCpus = new(float64) ramMb.RamMb = new(int64) diskMb.DiskMb = new(int64) return &AuroraJob{ jobConfig: jobConfig, resources: resources, metadata: make(map[string]*aurora.Metadata), portCount: 0, } }
go
func NewJob() Job { jobConfig := aurora.NewJobConfiguration() taskConfig := aurora.NewTaskConfig() jobKey := aurora.NewJobKey() // Job Config jobConfig.Key = jobKey jobConfig.TaskConfig = taskConfig // Task Config taskConfig.Job = jobKey taskConfig.Container = aurora.NewContainer() taskConfig.Container.Mesos = aurora.NewMesosContainer() // Resources numCpus := aurora.NewResource() ramMb := aurora.NewResource() diskMb := aurora.NewResource() resources := map[ResourceType]*aurora.Resource{CPU: numCpus, RAM: ramMb, DISK: diskMb} taskConfig.Resources = []*aurora.Resource{numCpus, ramMb, diskMb} numCpus.NumCpus = new(float64) ramMb.RamMb = new(int64) diskMb.DiskMb = new(int64) return &AuroraJob{ jobConfig: jobConfig, resources: resources, metadata: make(map[string]*aurora.Metadata), portCount: 0, } }
[ "func", "NewJob", "(", ")", "Job", "{", "jobConfig", ":=", "aurora", ".", "NewJobConfiguration", "(", ")", "\n", "taskConfig", ":=", "aurora", ".", "NewTaskConfig", "(", ")", "\n", "jobKey", ":=", "aurora", ".", "NewJobKey", "(", ")", "\n\n", "// Job Config", "jobConfig", ".", "Key", "=", "jobKey", "\n", "jobConfig", ".", "TaskConfig", "=", "taskConfig", "\n\n", "// Task Config", "taskConfig", ".", "Job", "=", "jobKey", "\n", "taskConfig", ".", "Container", "=", "aurora", ".", "NewContainer", "(", ")", "\n", "taskConfig", ".", "Container", ".", "Mesos", "=", "aurora", ".", "NewMesosContainer", "(", ")", "\n\n", "// Resources", "numCpus", ":=", "aurora", ".", "NewResource", "(", ")", "\n", "ramMb", ":=", "aurora", ".", "NewResource", "(", ")", "\n", "diskMb", ":=", "aurora", ".", "NewResource", "(", ")", "\n\n", "resources", ":=", "map", "[", "ResourceType", "]", "*", "aurora", ".", "Resource", "{", "CPU", ":", "numCpus", ",", "RAM", ":", "ramMb", ",", "DISK", ":", "diskMb", "}", "\n", "taskConfig", ".", "Resources", "=", "[", "]", "*", "aurora", ".", "Resource", "{", "numCpus", ",", "ramMb", ",", "diskMb", "}", "\n\n", "numCpus", ".", "NumCpus", "=", "new", "(", "float64", ")", "\n", "ramMb", ".", "RamMb", "=", "new", "(", "int64", ")", "\n", "diskMb", ".", "DiskMb", "=", "new", "(", "int64", ")", "\n\n", "return", "&", "AuroraJob", "{", "jobConfig", ":", "jobConfig", ",", "resources", ":", "resources", ",", "metadata", ":", "make", "(", "map", "[", "string", "]", "*", "aurora", ".", "Metadata", ")", ",", "portCount", ":", "0", ",", "}", "\n", "}" ]
// Create a Job object with everything initialized.
[ "Create", "a", "Job", "object", "with", "everything", "initialized", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/job.go#L82-L114
16,085
paypal/gorealis
job.go
Environment
func (j *AuroraJob) Environment(env string) Job { j.jobConfig.Key.Environment = env return j }
go
func (j *AuroraJob) Environment(env string) Job { j.jobConfig.Key.Environment = env return j }
[ "func", "(", "j", "*", "AuroraJob", ")", "Environment", "(", "env", "string", ")", "Job", "{", "j", ".", "jobConfig", ".", "Key", ".", "Environment", "=", "env", "\n", "return", "j", "\n", "}" ]
// Set Job Key environment.
[ "Set", "Job", "Key", "environment", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/job.go#L117-L120
16,086
paypal/gorealis
job.go
Role
func (j *AuroraJob) Role(role string) Job { j.jobConfig.Key.Role = role //Will be deprecated identity := &aurora.Identity{User: role} j.jobConfig.Owner = identity j.jobConfig.TaskConfig.Owner = identity return j }
go
func (j *AuroraJob) Role(role string) Job { j.jobConfig.Key.Role = role //Will be deprecated identity := &aurora.Identity{User: role} j.jobConfig.Owner = identity j.jobConfig.TaskConfig.Owner = identity return j }
[ "func", "(", "j", "*", "AuroraJob", ")", "Role", "(", "role", "string", ")", "Job", "{", "j", ".", "jobConfig", ".", "Key", ".", "Role", "=", "role", "\n\n", "//Will be deprecated", "identity", ":=", "&", "aurora", ".", "Identity", "{", "User", ":", "role", "}", "\n", "j", ".", "jobConfig", ".", "Owner", "=", "identity", "\n", "j", ".", "jobConfig", ".", "TaskConfig", ".", "Owner", "=", "identity", "\n", "return", "j", "\n", "}" ]
// Set Job Key Role.
[ "Set", "Job", "Key", "Role", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/job.go#L123-L131
16,087
paypal/gorealis
job.go
Name
func (j *AuroraJob) Name(name string) Job { j.jobConfig.Key.Name = name return j }
go
func (j *AuroraJob) Name(name string) Job { j.jobConfig.Key.Name = name return j }
[ "func", "(", "j", "*", "AuroraJob", ")", "Name", "(", "name", "string", ")", "Job", "{", "j", ".", "jobConfig", ".", "Key", ".", "Name", "=", "name", "\n", "return", "j", "\n", "}" ]
// Set Job Key Name.
[ "Set", "Job", "Key", "Name", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/job.go#L134-L137
16,088
paypal/gorealis
job.go
ExecutorName
func (j *AuroraJob) ExecutorName(name string) Job { if j.jobConfig.TaskConfig.ExecutorConfig == nil { j.jobConfig.TaskConfig.ExecutorConfig = aurora.NewExecutorConfig() } j.jobConfig.TaskConfig.ExecutorConfig.Name = name return j }
go
func (j *AuroraJob) ExecutorName(name string) Job { if j.jobConfig.TaskConfig.ExecutorConfig == nil { j.jobConfig.TaskConfig.ExecutorConfig = aurora.NewExecutorConfig() } j.jobConfig.TaskConfig.ExecutorConfig.Name = name return j }
[ "func", "(", "j", "*", "AuroraJob", ")", "ExecutorName", "(", "name", "string", ")", "Job", "{", "if", "j", ".", "jobConfig", ".", "TaskConfig", ".", "ExecutorConfig", "==", "nil", "{", "j", ".", "jobConfig", ".", "TaskConfig", ".", "ExecutorConfig", "=", "aurora", ".", "NewExecutorConfig", "(", ")", "\n", "}", "\n\n", "j", ".", "jobConfig", ".", "TaskConfig", ".", "ExecutorConfig", ".", "Name", "=", "name", "\n", "return", "j", "\n", "}" ]
// Set name of the executor that will the task will be configured to.
[ "Set", "name", "of", "the", "executor", "that", "will", "the", "task", "will", "be", "configured", "to", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/job.go#L140-L148
16,089
paypal/gorealis
job.go
ExecutorData
func (j *AuroraJob) ExecutorData(data string) Job { if j.jobConfig.TaskConfig.ExecutorConfig == nil { j.jobConfig.TaskConfig.ExecutorConfig = aurora.NewExecutorConfig() } j.jobConfig.TaskConfig.ExecutorConfig.Data = data return j }
go
func (j *AuroraJob) ExecutorData(data string) Job { if j.jobConfig.TaskConfig.ExecutorConfig == nil { j.jobConfig.TaskConfig.ExecutorConfig = aurora.NewExecutorConfig() } j.jobConfig.TaskConfig.ExecutorConfig.Data = data return j }
[ "func", "(", "j", "*", "AuroraJob", ")", "ExecutorData", "(", "data", "string", ")", "Job", "{", "if", "j", ".", "jobConfig", ".", "TaskConfig", ".", "ExecutorConfig", "==", "nil", "{", "j", ".", "jobConfig", ".", "TaskConfig", ".", "ExecutorConfig", "=", "aurora", ".", "NewExecutorConfig", "(", ")", "\n", "}", "\n\n", "j", ".", "jobConfig", ".", "TaskConfig", ".", "ExecutorConfig", ".", "Data", "=", "data", "\n", "return", "j", "\n", "}" ]
// Will be included as part of entire task inside the scheduler that will be serialized.
[ "Will", "be", "included", "as", "part", "of", "entire", "task", "inside", "the", "scheduler", "that", "will", "be", "serialized", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/job.go#L151-L159
16,090
paypal/gorealis
job.go
MaxFailure
func (j *AuroraJob) MaxFailure(maxFail int32) Job { j.jobConfig.TaskConfig.MaxTaskFailures = maxFail return j }
go
func (j *AuroraJob) MaxFailure(maxFail int32) Job { j.jobConfig.TaskConfig.MaxTaskFailures = maxFail return j }
[ "func", "(", "j", "*", "AuroraJob", ")", "MaxFailure", "(", "maxFail", "int32", ")", "Job", "{", "j", ".", "jobConfig", ".", "TaskConfig", ".", "MaxTaskFailures", "=", "maxFail", "\n", "return", "j", "\n", "}" ]
// How many failures to tolerate before giving up.
[ "How", "many", "failures", "to", "tolerate", "before", "giving", "up", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/job.go#L189-L192
16,091
paypal/gorealis
job.go
InstanceCount
func (j *AuroraJob) InstanceCount(instCount int32) Job { j.jobConfig.InstanceCount = instCount return j }
go
func (j *AuroraJob) InstanceCount(instCount int32) Job { j.jobConfig.InstanceCount = instCount return j }
[ "func", "(", "j", "*", "AuroraJob", ")", "InstanceCount", "(", "instCount", "int32", ")", "Job", "{", "j", ".", "jobConfig", ".", "InstanceCount", "=", "instCount", "\n", "return", "j", "\n", "}" ]
// How many instances of the job to run
[ "How", "many", "instances", "of", "the", "job", "to", "run" ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/job.go#L195-L198
16,092
paypal/gorealis
job.go
IsService
func (j *AuroraJob) IsService(isService bool) Job { j.jobConfig.TaskConfig.IsService = isService return j }
go
func (j *AuroraJob) IsService(isService bool) Job { j.jobConfig.TaskConfig.IsService = isService return j }
[ "func", "(", "j", "*", "AuroraJob", ")", "IsService", "(", "isService", "bool", ")", "Job", "{", "j", ".", "jobConfig", ".", "TaskConfig", ".", "IsService", "=", "isService", "\n", "return", "j", "\n", "}" ]
// Restart the job's tasks if they fail
[ "Restart", "the", "job", "s", "tasks", "if", "they", "fail" ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/job.go#L216-L219
16,093
paypal/gorealis
job.go
AddLabel
func (j *AuroraJob) AddLabel(key string, value string) Job { if _, ok := j.metadata[key]; ok { j.metadata[key].Value = value } else { j.metadata[key] = &aurora.Metadata{Key: key, Value: value} j.jobConfig.TaskConfig.Metadata = append(j.jobConfig.TaskConfig.Metadata, j.metadata[key]) } return j }
go
func (j *AuroraJob) AddLabel(key string, value string) Job { if _, ok := j.metadata[key]; ok { j.metadata[key].Value = value } else { j.metadata[key] = &aurora.Metadata{Key: key, Value: value} j.jobConfig.TaskConfig.Metadata = append(j.jobConfig.TaskConfig.Metadata, j.metadata[key]) } return j }
[ "func", "(", "j", "*", "AuroraJob", ")", "AddLabel", "(", "key", "string", ",", "value", "string", ")", "Job", "{", "if", "_", ",", "ok", ":=", "j", ".", "metadata", "[", "key", "]", ";", "ok", "{", "j", ".", "metadata", "[", "key", "]", ".", "Value", "=", "value", "\n", "}", "else", "{", "j", ".", "metadata", "[", "key", "]", "=", "&", "aurora", ".", "Metadata", "{", "Key", ":", "key", ",", "Value", ":", "value", "}", "\n", "j", ".", "jobConfig", ".", "TaskConfig", ".", "Metadata", "=", "append", "(", "j", ".", "jobConfig", ".", "TaskConfig", ".", "Metadata", ",", "j", ".", "metadata", "[", "key", "]", ")", "\n", "}", "\n", "return", "j", "\n", "}" ]
// Adds a Mesos label to the job. Note that Aurora will add the // prefix "org.apache.aurora.metadata." to the beginning of each key.
[ "Adds", "a", "Mesos", "label", "to", "the", "job", ".", "Note", "that", "Aurora", "will", "add", "the", "prefix", "org", ".", "apache", ".", "aurora", ".", "metadata", ".", "to", "the", "beginning", "of", "each", "key", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/job.go#L247-L255
16,094
paypal/gorealis
job.go
AddNamedPorts
func (j *AuroraJob) AddNamedPorts(names ...string) Job { j.portCount += len(names) for _, name := range names { j.jobConfig.TaskConfig.Resources = append(j.jobConfig.TaskConfig.Resources, &aurora.Resource{NamedPort: &name}) } return j }
go
func (j *AuroraJob) AddNamedPorts(names ...string) Job { j.portCount += len(names) for _, name := range names { j.jobConfig.TaskConfig.Resources = append(j.jobConfig.TaskConfig.Resources, &aurora.Resource{NamedPort: &name}) } return j }
[ "func", "(", "j", "*", "AuroraJob", ")", "AddNamedPorts", "(", "names", "...", "string", ")", "Job", "{", "j", ".", "portCount", "+=", "len", "(", "names", ")", "\n", "for", "_", ",", "name", ":=", "range", "names", "{", "j", ".", "jobConfig", ".", "TaskConfig", ".", "Resources", "=", "append", "(", "j", ".", "jobConfig", ".", "TaskConfig", ".", "Resources", ",", "&", "aurora", ".", "Resource", "{", "NamedPort", ":", "&", "name", "}", ")", "\n", "}", "\n\n", "return", "j", "\n", "}" ]
// Add a named port to the job configuration These are random ports as it's // not currently possible to request specific ports using Aurora.
[ "Add", "a", "named", "port", "to", "the", "job", "configuration", "These", "are", "random", "ports", "as", "it", "s", "not", "currently", "possible", "to", "request", "specific", "ports", "using", "Aurora", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/job.go#L259-L266
16,095
paypal/gorealis
job.go
AddPorts
func (j *AuroraJob) AddPorts(num int) Job { start := j.portCount j.portCount += num for i := start; i < j.portCount; i++ { portName := "org.apache.aurora.port." + strconv.Itoa(i) j.jobConfig.TaskConfig.Resources = append(j.jobConfig.TaskConfig.Resources, &aurora.Resource{NamedPort: &portName}) } return j }
go
func (j *AuroraJob) AddPorts(num int) Job { start := j.portCount j.portCount += num for i := start; i < j.portCount; i++ { portName := "org.apache.aurora.port." + strconv.Itoa(i) j.jobConfig.TaskConfig.Resources = append(j.jobConfig.TaskConfig.Resources, &aurora.Resource{NamedPort: &portName}) } return j }
[ "func", "(", "j", "*", "AuroraJob", ")", "AddPorts", "(", "num", "int", ")", "Job", "{", "start", ":=", "j", ".", "portCount", "\n", "j", ".", "portCount", "+=", "num", "\n", "for", "i", ":=", "start", ";", "i", "<", "j", ".", "portCount", ";", "i", "++", "{", "portName", ":=", "\"", "\"", "+", "strconv", ".", "Itoa", "(", "i", ")", "\n", "j", ".", "jobConfig", ".", "TaskConfig", ".", "Resources", "=", "append", "(", "j", ".", "jobConfig", ".", "TaskConfig", ".", "Resources", ",", "&", "aurora", ".", "Resource", "{", "NamedPort", ":", "&", "portName", "}", ")", "\n", "}", "\n\n", "return", "j", "\n", "}" ]
// Adds a request for a number of ports to the job configuration. The names chosen for these ports // will be org.apache.aurora.port.X, where X is the current port count for the job configuration // starting at 0. These are random ports as it's not currently possible to request // specific ports using Aurora.
[ "Adds", "a", "request", "for", "a", "number", "of", "ports", "to", "the", "job", "configuration", ".", "The", "names", "chosen", "for", "these", "ports", "will", "be", "org", ".", "apache", ".", "aurora", ".", "port", ".", "X", "where", "X", "is", "the", "current", "port", "count", "for", "the", "job", "configuration", "starting", "at", "0", ".", "These", "are", "random", "ports", "as", "it", "s", "not", "currently", "possible", "to", "request", "specific", "ports", "using", "Aurora", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/job.go#L272-L281
16,096
paypal/gorealis
job.go
Container
func (j *AuroraJob) Container(container Container) Job { j.jobConfig.TaskConfig.Container = container.Build() return j }
go
func (j *AuroraJob) Container(container Container) Job { j.jobConfig.TaskConfig.Container = container.Build() return j }
[ "func", "(", "j", "*", "AuroraJob", ")", "Container", "(", "container", "Container", ")", "Job", "{", "j", ".", "jobConfig", ".", "TaskConfig", ".", "Container", "=", "container", ".", "Build", "(", ")", "\n\n", "return", "j", "\n", "}" ]
// Set a container to run for the job configuration to run.
[ "Set", "a", "container", "to", "run", "for", "the", "job", "configuration", "to", "run", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/job.go#L327-L331
16,097
paypal/gorealis
job.go
PartitionPolicy
func (j *AuroraJob) PartitionPolicy(policy *aurora.PartitionPolicy) Job { j.jobConfig.TaskConfig.PartitionPolicy = policy return j }
go
func (j *AuroraJob) PartitionPolicy(policy *aurora.PartitionPolicy) Job { j.jobConfig.TaskConfig.PartitionPolicy = policy return j }
[ "func", "(", "j", "*", "AuroraJob", ")", "PartitionPolicy", "(", "policy", "*", "aurora", ".", "PartitionPolicy", ")", "Job", "{", "j", ".", "jobConfig", ".", "TaskConfig", ".", "PartitionPolicy", "=", "policy", "\n", "return", "j", "\n", "}" ]
// Set a partition policy for the job configuration to implement.
[ "Set", "a", "partition", "policy", "for", "the", "job", "configuration", "to", "implement", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/job.go#L334-L337
16,098
paypal/gorealis
job.go
Tier
func (j *AuroraJob) Tier(tier string) Job { j.jobConfig.TaskConfig.Tier = &tier return j }
go
func (j *AuroraJob) Tier(tier string) Job { j.jobConfig.TaskConfig.Tier = &tier return j }
[ "func", "(", "j", "*", "AuroraJob", ")", "Tier", "(", "tier", "string", ")", "Job", "{", "j", ".", "jobConfig", ".", "TaskConfig", ".", "Tier", "=", "&", "tier", "\n\n", "return", "j", "\n", "}" ]
// Set the Tier for the Job.
[ "Set", "the", "Tier", "for", "the", "Job", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/job.go#L340-L344
16,099
paypal/gorealis
job.go
SlaPolicy
func (j *AuroraJob) SlaPolicy(policy *aurora.SlaPolicy) Job { j.jobConfig.TaskConfig.SlaPolicy = policy return j }
go
func (j *AuroraJob) SlaPolicy(policy *aurora.SlaPolicy) Job { j.jobConfig.TaskConfig.SlaPolicy = policy return j }
[ "func", "(", "j", "*", "AuroraJob", ")", "SlaPolicy", "(", "policy", "*", "aurora", ".", "SlaPolicy", ")", "Job", "{", "j", ".", "jobConfig", ".", "TaskConfig", ".", "SlaPolicy", "=", "policy", "\n\n", "return", "j", "\n", "}" ]
// Set an SlaPolicy for the Job.
[ "Set", "an", "SlaPolicy", "for", "the", "Job", "." ]
e16e390afe057e029334bbbac63942323d4ea50d
https://github.com/paypal/gorealis/blob/e16e390afe057e029334bbbac63942323d4ea50d/job.go#L347-L351