通过 Java mysql admin-api 启动和停止云 SQL
Start and Stop Cloud SQL via Java mysql admin-api
我找不到使用 java mysql admin-api.[=15= 简单地启动和停止 Cloud SQL 实例的方法]
我找到了这个解释如何通过 gcloud 启动和停止 Cloud SQL 实例的官方 google 文档:https://cloud.google.com/sql/docs/mysql/start-stop-restart-instance 但我无法通过java 使用 mysql 管理员-api,
有人可以帮助我吗?
一般情况下,Cloud SQL Admin API for Java用于您要查找的操作。如果您使用的是 Maven,则可以将库添加到您的项目中,将以下代码行添加到 pom.xml
配置文件中:
<project>
<dependencies>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-sqladmin</artifactId>
<version>v1beta4-rev48-1.23.0</version>
</dependency>
</dependencies>
</project>
编辑:
据我在 documentation, the underlying API uses the Instance.Patch
method for starting and stopping instances, although I cannot find any specific information about how to do it. However, you can find more relevant information yourself in the Instances:Patch 页面中所见。我会继续寻找更多信息,如果我找到相关信息,我会 post 在下面对此答案发表评论。
编辑 2:
我一直在使用 Google APIs Explorer、PROJECT_ID
、SQL_INSTANCE_ID
和 JSON 主体进行一些测试,比如这个:
{
"settings": {
"activationPolicy": "YOUR_PREFERED_STATE"
}
}
根据文档:
The activation policy specifies when the instance is activated; it is
applicable only when the instance state is RUNNABLE. Valid values:
ALWAYS: The instance is on, and remains so even in the absence of
connection requests. NEVER: The instance is off; it is not activated,
even if a connection request arrives. ON_DEMAND: First Generation
instances only. The instance responds to incoming requests, and turns
itself off when not in use. Instances with PER_USE pricing turn off
after 15 minutes of inactivity. Instances with PER_PACKAGE pricing
turn off after 12 hours of inactivity.
我已经尝试 运行 API NEVER 和 ALWAYS 状态,我的 Cloud SQL 实例停止并相应地启动。因此,在您的情况下,返回 Java 的管理员 API,您应该查看实例的 Settings,特别是 this method:
public Settings setActivationPolicy(java.lang.String activationPolicy)
将 激活策略 更改为从不或始终应该是您在这里需要的,尽管您可以查看其他可能的实例状态,以防它们更符合您的要求。
我找不到使用 java mysql admin-api.[=15= 简单地启动和停止 Cloud SQL 实例的方法]
我找到了这个解释如何通过 gcloud 启动和停止 Cloud SQL 实例的官方 google 文档:https://cloud.google.com/sql/docs/mysql/start-stop-restart-instance 但我无法通过java 使用 mysql 管理员-api,
有人可以帮助我吗?
一般情况下,Cloud SQL Admin API for Java用于您要查找的操作。如果您使用的是 Maven,则可以将库添加到您的项目中,将以下代码行添加到 pom.xml
配置文件中:
<project>
<dependencies>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-sqladmin</artifactId>
<version>v1beta4-rev48-1.23.0</version>
</dependency>
</dependencies>
</project>
编辑:
据我在 documentation, the underlying API uses the Instance.Patch
method for starting and stopping instances, although I cannot find any specific information about how to do it. However, you can find more relevant information yourself in the Instances:Patch 页面中所见。我会继续寻找更多信息,如果我找到相关信息,我会 post 在下面对此答案发表评论。
编辑 2:
我一直在使用 Google APIs Explorer、PROJECT_ID
、SQL_INSTANCE_ID
和 JSON 主体进行一些测试,比如这个:
{
"settings": {
"activationPolicy": "YOUR_PREFERED_STATE"
}
}
根据文档:
The activation policy specifies when the instance is activated; it is applicable only when the instance state is RUNNABLE. Valid values: ALWAYS: The instance is on, and remains so even in the absence of connection requests. NEVER: The instance is off; it is not activated, even if a connection request arrives. ON_DEMAND: First Generation instances only. The instance responds to incoming requests, and turns itself off when not in use. Instances with PER_USE pricing turn off after 15 minutes of inactivity. Instances with PER_PACKAGE pricing turn off after 12 hours of inactivity.
我已经尝试 运行 API NEVER 和 ALWAYS 状态,我的 Cloud SQL 实例停止并相应地启动。因此,在您的情况下,返回 Java 的管理员 API,您应该查看实例的 Settings,特别是 this method:
public Settings setActivationPolicy(java.lang.String activationPolicy)
将 激活策略 更改为从不或始终应该是您在这里需要的,尽管您可以查看其他可能的实例状态,以防它们更符合您的要求。