Package com.netflix.appinfo
Class InstanceInfo
- java.lang.Object
-
- com.netflix.appinfo.InstanceInfo
-
@Serializer("com.netflix.discovery.converters.EntityBodyConverter") public class InstanceInfo extends java.lang.Object
The class that holds information required for registration with Eureka Server and to be discovered by other components.@Autoannotated fields are serialized as is; Other fields are serialized as specified by the@Serializer.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInstanceInfo.ActionTypestatic classInstanceInfo.Builderstatic classInstanceInfo.InstanceStatusstatic classInstanceInfo.PortTypestatic classInstanceInfo.PortWrapperInstanceInfoJSON and XML format for port information does not follow the usual conventions, which makes its mapping complicated.
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_COUNTRY_IDstatic intDEFAULT_PORTstatic intDEFAULT_SECURE_PORT
-
Constructor Summary
Constructors Constructor Description InstanceInfo(InstanceInfo ii)shallow copy constructor.InstanceInfo(java.lang.String instanceId, java.lang.String appName, java.lang.String appGroupName, java.lang.String ipAddr, java.lang.String sid, InstanceInfo.PortWrapper port, InstanceInfo.PortWrapper securePort, java.lang.String homePageUrl, java.lang.String statusPageUrl, java.lang.String healthCheckUrl, java.lang.String secureHealthCheckUrl, java.lang.String vipAddress, java.lang.String secureVipAddress, int countryId, DataCenterInfo dataCenterInfo, java.lang.String hostName, InstanceInfo.InstanceStatus status, InstanceInfo.InstanceStatus overriddenStatus, InstanceInfo.InstanceStatus overriddenStatusAlt, LeaseInfo leaseInfo, java.lang.Boolean isCoordinatingDiscoveryServer, java.util.HashMap<java.lang.String,java.lang.String> metadata, java.lang.Long lastUpdatedTimestamp, java.lang.Long lastDirtyTimestamp, InstanceInfo.ActionType actionType, java.lang.String asgName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)InstanceInfo.ActionTypegetActionType()Returns the type of action done on the instance in the server.Primarily used for updating deltas in theEurekaClientinstance.java.lang.StringgetAppGroupName()java.lang.StringgetAppName()Return the name of the application registering with discovery.java.lang.StringgetASGName()Get AWS autoscaling group name if any.intgetCountryId()Deprecated.DataCenterInfogetDataCenterInfo()Returns data center information identifying if it is AWS or not.java.lang.StringgetHealthCheckUrl()java.util.Set<java.lang.String>getHealthCheckUrls()Gets the absolute URLs for the health check page for both secure and non-secure protocols.java.lang.StringgetHomePageUrl()Gets the home pageURLset for this instance.java.lang.StringgetHostName()Return the default network address to connect to this instance.java.lang.StringgetId()Returns the unique id of the instance.java.lang.StringgetInstanceId()java.lang.StringgetIPAddr()Returns the ip address of the instance.java.lang.LonggetLastDirtyTimestamp()Gets the last time stamp when this instance was touched.longgetLastUpdatedTimestamp()Returns the time elapsed since epoch since the instance status has been last updated.LeaseInfogetLeaseInfo()Returns the lease information regarding when it expires.java.util.Map<java.lang.String,java.lang.String>getMetadata()Returns all application specific metadata set on the instance.InstanceInfo.InstanceStatusgetOverriddenStatus()Returns the overridden status if any of the instance.intgetPort()Returns the port number that is used for servicing requests.java.lang.StringgetSecureHealthCheckUrl()intgetSecurePort()Returns the secure port that is used for servicing requests.java.lang.StringgetSecureVipAddress()Get the Secure Virtual Internet Protocol address for this instance.java.lang.StringgetSID()Deprecated.InstanceInfo.InstanceStatusgetStatus()Returns the status of the instance.java.lang.StringgetStatusPageUrl()Gets the status pageURLset for this instance.java.lang.StringgetVersion()Deprecated.java.lang.StringgetVIPAddress()Gets the Virtual Internet Protocol address for this instance.static java.lang.StringgetZone(java.lang.String[] availZones, InstanceInfo myInfo)Get the zone that a particular instance is in.inthashCode()java.lang.BooleanisCoordinatingDiscoveryServer()Finds if this instance is the coordinating discovery server.booleanisDirty()Returns whether any state changed so thatEurekaClientcan check whether to retransmit info or not on the next heartbeat.java.lang.LongisDirtyWithTime()booleanisPortEnabled(InstanceInfo.PortType type)Checks whether a port is enabled for traffic or not.voidsetActionType(InstanceInfo.ActionType actionType)Set the action type performed on this instance in the server.voidsetIsCoordinatingDiscoveryServer()Sets a flag if this instance is the same as the discovery server that is return the instances.voidsetIsDirty()Sets the dirty flag so that the instance information can be carried to the discovery server on the next heartbeat.voidsetIsDirty(boolean isDirty)Deprecated.usesetIsDirty()andunsetIsDirty(long)to set and unsetlongsetIsDirtyWithTime()Set the dirty flag, and also return the timestamp of the isDirty eventvoidsetLastDirtyTimestamp(java.lang.Long lastDirtyTimestamp)Set the time indicating that the instance was touched.voidsetLastUpdatedTimestamp()Set the update time for this instance when the status was update.voidsetLeaseInfo(LeaseInfo info)Sets the lease information regarding when it expires.voidsetOverriddenStatus(InstanceInfo.InstanceStatus status)Sets the overridden status for this instance.Normally set by an external process to disable instance from taking traffic.voidsetSID(java.lang.String sid)Deprecated.InstanceInfo.InstanceStatussetStatus(InstanceInfo.InstanceStatus status)Set the status for this instance.InstanceInfo.InstanceStatussetStatus(InstanceInfo.InstanceStatus expected, InstanceInfo.InstanceStatus status)Set the status for this instance only when the current status matches the expected status.voidsetStatusWithoutDirty(InstanceInfo.InstanceStatus status)Set the status for this instance without updating the dirty timestamp.java.lang.StringtoString()voidunsetIsDirty(long unsetDirtyTimestamp)Unset the dirty flag iff the unsetDirtyTimestamp matches the lastDirtyTimestamp.
-
-
-
Field Detail
-
DEFAULT_PORT
public static final int DEFAULT_PORT
- See Also:
- Constant Field Values
-
DEFAULT_SECURE_PORT
public static final int DEFAULT_SECURE_PORT
- See Also:
- Constant Field Values
-
DEFAULT_COUNTRY_ID
public static final int DEFAULT_COUNTRY_ID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
InstanceInfo
public InstanceInfo(java.lang.String instanceId, java.lang.String appName, java.lang.String appGroupName, java.lang.String ipAddr, java.lang.String sid, InstanceInfo.PortWrapper port, InstanceInfo.PortWrapper securePort, java.lang.String homePageUrl, java.lang.String statusPageUrl, java.lang.String healthCheckUrl, java.lang.String secureHealthCheckUrl, java.lang.String vipAddress, java.lang.String secureVipAddress, int countryId, DataCenterInfo dataCenterInfo, java.lang.String hostName, InstanceInfo.InstanceStatus status, InstanceInfo.InstanceStatus overriddenStatus, InstanceInfo.InstanceStatus overriddenStatusAlt, LeaseInfo leaseInfo, java.lang.Boolean isCoordinatingDiscoveryServer, java.util.HashMap<java.lang.String,java.lang.String> metadata, java.lang.Long lastUpdatedTimestamp, java.lang.Long lastDirtyTimestamp, InstanceInfo.ActionType actionType, java.lang.String asgName)
-
InstanceInfo
public InstanceInfo(InstanceInfo ii)
shallow copy constructor.- Parameters:
ii- The object to copy
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
getInstanceId
public java.lang.String getInstanceId()
- Returns:
- the raw instanceId. For compatibility, prefer to use
getId()
-
getAppName
public java.lang.String getAppName()
Return the name of the application registering with discovery.- Returns:
- the string denoting the application name.
-
getAppGroupName
public java.lang.String getAppGroupName()
-
getHostName
public java.lang.String getHostName()
Return the default network address to connect to this instance. Typically this would be the fully qualified public hostname. However the user can configure theEurekaInstanceConfigto change the default value used to populate this field using theEurekaInstanceConfig.getDefaultAddressResolutionOrder()property. If a use case need more specific hostnames or ips, please use data fromgetDataCenterInfo(). For legacy reasons, it is difficult to introduce a new address-type field that is agnostic to hostname/ip.- Returns:
- the default address (by default the public hostname)
-
setSID
@Deprecated public void setSID(java.lang.String sid)
Deprecated.
-
getSID
@Deprecated public java.lang.String getSID()
Deprecated.
-
getId
public java.lang.String getId()
Returns the unique id of the instance. (Note) now that id is set at creation time within the instanceProvider, why do the other checks? This is still necessary for backwards compatibility when upgrading in a deployment with multiple client versions (some with the change, some without).- Returns:
- the unique id.
-
getIPAddr
public java.lang.String getIPAddr()
Returns the ip address of the instance.- Returns:
- - the ip address, in AWS scenario it is a private IP.
-
getPort
public int getPort()
Returns the port number that is used for servicing requests.- Returns:
- - the non-secure port number.
-
getStatus
public InstanceInfo.InstanceStatus getStatus()
Returns the status of the instance.- Returns:
- the status indicating whether the instance can handle requests.
-
getOverriddenStatus
public InstanceInfo.InstanceStatus getOverriddenStatus()
Returns the overridden status if any of the instance.- Returns:
- the status indicating whether an external process has changed the status.
-
getDataCenterInfo
public DataCenterInfo getDataCenterInfo()
Returns data center information identifying if it is AWS or not.- Returns:
- the data center information.
-
getLeaseInfo
public LeaseInfo getLeaseInfo()
Returns the lease information regarding when it expires.- Returns:
- the lease information of this instance.
-
setLeaseInfo
public void setLeaseInfo(LeaseInfo info)
Sets the lease information regarding when it expires.- Parameters:
info- the lease information of this instance.
-
getMetadata
public java.util.Map<java.lang.String,java.lang.String> getMetadata()
Returns all application specific metadata set on the instance.- Returns:
- application specific metadata.
-
getCountryId
@Deprecated public int getCountryId()
Deprecated.
-
getSecurePort
public int getSecurePort()
Returns the secure port that is used for servicing requests.- Returns:
- the secure port.
-
isPortEnabled
public boolean isPortEnabled(InstanceInfo.PortType type)
Checks whether a port is enabled for traffic or not.- Parameters:
type- indicates whether it is secure or non-secure port.- Returns:
- true if the port is enabled, false otherwise.
-
getLastUpdatedTimestamp
public long getLastUpdatedTimestamp()
Returns the time elapsed since epoch since the instance status has been last updated.- Returns:
- the time elapsed since epoch since the instance has been last updated.
-
setLastUpdatedTimestamp
public void setLastUpdatedTimestamp()
Set the update time for this instance when the status was update.
-
getHomePageUrl
public java.lang.String getHomePageUrl()
Gets the home pageURLset for this instance.- Returns:
- home page
URL
-
getStatusPageUrl
public java.lang.String getStatusPageUrl()
Gets the status pageURLset for this instance.- Returns:
- status page
URL
-
getHealthCheckUrls
public java.util.Set<java.lang.String> getHealthCheckUrls()
Gets the absolute URLs for the health check page for both secure and non-secure protocols. If the port is not enabled then the URL is excluded.- Returns:
- A Set containing the string representation of health check urls for secure and non secure protocols
-
getHealthCheckUrl
public java.lang.String getHealthCheckUrl()
-
getSecureHealthCheckUrl
public java.lang.String getSecureHealthCheckUrl()
-
getVIPAddress
public java.lang.String getVIPAddress()
Gets the Virtual Internet Protocol address for this instance. Defaults to hostname if not specified.- Returns:
- - The Virtual Internet Protocol address
-
getSecureVipAddress
public java.lang.String getSecureVipAddress()
Get the Secure Virtual Internet Protocol address for this instance. Defaults to hostname if not specified.- Returns:
- - The Secure Virtual Internet Protocol address.
-
getLastDirtyTimestamp
public java.lang.Long getLastDirtyTimestamp()
Gets the last time stamp when this instance was touched.- Returns:
- last timestamp when this instance was touched.
-
setLastDirtyTimestamp
public void setLastDirtyTimestamp(java.lang.Long lastDirtyTimestamp)
Set the time indicating that the instance was touched.- Parameters:
lastDirtyTimestamp- time when the instance was touched.
-
setStatus
public InstanceInfo.InstanceStatus setStatus(InstanceInfo.InstanceStatus status)
Set the status for this instance.- Parameters:
status- status for this instance.- Returns:
- the prev status if a different status from the current was set, null otherwise
-
setStatus
public InstanceInfo.InstanceStatus setStatus(InstanceInfo.InstanceStatus expected, InstanceInfo.InstanceStatus status)
Set the status for this instance only when the current status matches the expected status.- Parameters:
expected- status for this instance.status- status to set for this instance.- Returns:
- the prev status if a different status from the current was set, null otherwise
-
setStatusWithoutDirty
public void setStatusWithoutDirty(InstanceInfo.InstanceStatus status)
Set the status for this instance without updating the dirty timestamp.- Parameters:
status- status for this instance.
-
setOverriddenStatus
public void setOverriddenStatus(InstanceInfo.InstanceStatus status)
Sets the overridden status for this instance.Normally set by an external process to disable instance from taking traffic.- Parameters:
status- overridden status for this instance.
-
isDirty
public boolean isDirty()
Returns whether any state changed so thatEurekaClientcan check whether to retransmit info or not on the next heartbeat.- Returns:
- true if the
InstanceInfois dirty, false otherwise.
-
isDirtyWithTime
public java.lang.Long isDirtyWithTime()
- Returns:
- the lastDirtyTimestamp if is dirty, null otherwise.
-
setIsDirty
@Deprecated public void setIsDirty(boolean isDirty)
Deprecated.usesetIsDirty()andunsetIsDirty(long)to set and unsetSets the dirty flag so that the instance information can be carried to the discovery server on the next heartbeat.
- Parameters:
isDirty- true if dirty, false otherwise.
-
setIsDirty
public void setIsDirty()
Sets the dirty flag so that the instance information can be carried to the discovery server on the next heartbeat.
-
setIsDirtyWithTime
public long setIsDirtyWithTime()
Set the dirty flag, and also return the timestamp of the isDirty event- Returns:
- the timestamp when the isDirty flag is set
-
unsetIsDirty
public void unsetIsDirty(long unsetDirtyTimestamp)
Unset the dirty flag iff the unsetDirtyTimestamp matches the lastDirtyTimestamp. No-op if lastDirtyTimestamp > unsetDirtyTimestamp- Parameters:
unsetDirtyTimestamp- the expected lastDirtyTimestamp to unset.
-
setIsCoordinatingDiscoveryServer
public void setIsCoordinatingDiscoveryServer()
Sets a flag if this instance is the same as the discovery server that is return the instances. This flag is used by the discovery clients to identity the discovery server which is coordinating/returning the information.
-
isCoordinatingDiscoveryServer
public java.lang.Boolean isCoordinatingDiscoveryServer()
Finds if this instance is the coordinating discovery server.- Returns:
- - true, if this instance is the coordinating discovery server, false otherwise.
-
getActionType
public InstanceInfo.ActionType getActionType()
Returns the type of action done on the instance in the server.Primarily used for updating deltas in theEurekaClientinstance.- Returns:
- action type done on the instance.
-
setActionType
public void setActionType(InstanceInfo.ActionType actionType)
Set the action type performed on this instance in the server.- Parameters:
actionType- action type done on the instance.
-
getASGName
public java.lang.String getASGName()
Get AWS autoscaling group name if any.- Returns:
- autoscaling group name of this instance.
-
getVersion
@Deprecated public java.lang.String getVersion()
Deprecated.Returns the specification version of this application.- Returns:
- the string indicating the version of the application.
-
getZone
public static java.lang.String getZone(java.lang.String[] availZones, InstanceInfo myInfo)Get the zone that a particular instance is in. Note that for AWS deployments, myInfo should contain AWS dataCenterInfo which should contain the AWS zone of the instance, and availZones is ignored.- Parameters:
availZones- the list of available zones for non-AWS deploymentsmyInfo- - The InstanceInfo object of the instance.- Returns:
- - The zone in which the particular instance belongs to.
-
-