跳到主要内容

Project

项目管理包含两个核心类:Projects(项目集合管理器)和 Project(项目实体)。Projects 提供项目级的增删改查操作,Project 封装单个项目的属性和行为。

获取实例​

// 获取 Projects 集合
Projects projects = odps.projects();

// 获取当前默认项目
Project project = projects.get();

// 获取指定项目
Project project = projects.get("project_name");

Project 实现了 LazyLoad 接口,调用 get() 不会加载完整属性。首次访问属性时自动加载。

Projects 方法​

get​

public Project get() throws OdpsException
public Project get(String projectName) throws OdpsException

返回值:Project 对象(延迟加载)


exists​

public boolean exists(String projectName) throws OdpsException

返回值:项目存在返回 true


create​

public void create(CreateProjectParam param) throws OdpsException

CreateProjectParam Builder 方法:

方法说明必填
name(String)项目名称(2-64字符)是
owner(String)项目所有者是
defaultCluster(String)默认计算集群是
comment(String)项目描述否
superAdmin(String)超级管理员否
properties(Map)项目属性(覆盖设置)否
appendProperty(String, String)追加属性否
groupName(String)项目组名称否
defaultQuotaId(String)默认计算配额 ID否

createExternalProject​

创建外部项目(联邦查询)。

public void createExternalProject(String projectName, String comment,
String refProjectName,
Project.ExternalProjectProperties extProperties)
throws OdpsException

参数:

参数类型说明
projectNameString外部项目名称
commentString项目描述
refProjectNameString关联的内部项目名称
extPropertiesExternalProjectProperties外部数据源配置

updateProject​

更新项目属性、状态、所有者等信息。

public void updateProject(String projectName, Map<String, String> properties) throws OdpsException
public void updateProject(String projectName, Project.Status status, String owner, String comment,
Map<String, String> properties, List<Project.Cluster> clusters) throws OdpsException
public void updateProject(String projectName, Project.Status status, String owner, String comment,
Map<String, String> properties, List<Project.Cluster> clusters,
QuotaIdentifier defaultQuota) throws OdpsException

参数:

参数类型说明
projectNameString项目名称
propertiesMap<String, String>项目属性键值对
statusProject.Status项目状态:AVAILABLE、FROZEN、DELETING
ownerString项目所有者账号
commentString项目描述
clustersList<Project.Cluster>计算集群列表
defaultQuotaQuotaIdentifier默认计算配额

示例:

// 更新项目属性
Map<String, String> props = new HashMap<>();
props.put("odps.security.ip.whitelist", "10.0.0.0/8");
odps.projects().updateProject("my_project", props);

// 冻结项目
odps.projects().updateProject("my_project", Project.Status.FROZEN,
null, null, null, null);

delete​

public Instance delete(String projectName, boolean isImmediate) throws OdpsException

参数:

参数类型说明
projectNameString项目名称
isImmediatebooleantrue 物理删除(不可逆);false 逻辑删除(可恢复)

返回值:物理删除时返回操作 Instance;逻辑删除返回 null


iterator / iterable​

public Iterator<Project> iterator(String owner)
public Iterable<Project> iterable(String owner)
public Iterator<Project> iteratorByFilter(ProjectFilter filter)

ProjectFilter 属性:

属性说明
owner项目所有者(精确匹配)
name项目名称前缀匹配
user项目使用者
groupName项目组名称
tenantId租户 ID
regionId地域 ID
quotaNickname配额别名

Project 属性方法​

基础属性​

方法返回类型说明
getName()String项目名称
getComment()String项目描述
getOwner()String项目所有者
getRegionId()String所属地域(如 cn-shanghai)
getCreatedTime()Date创建时间
getLastModifiedTime()Date最后修改时间

getType​

public ProjectType getType()

返回值:

枚举值说明
MANAGED原生存储项目(默认)
EXTERNAL旧版外部存储(兼容)
EXTERNAL_V2新版外部存储(推荐)

getStatus​

public Status getStatus()

返回值:

枚举值说明
AVAILABLE正常可用
READONLY只读模式
DELETING删除中
FROZEN被冻结
UNKOWN状态未知(需 reload())

getProperties​

获取项目显式配置的属性集合(不含继承配置)。

public Map<String, String> getProperties()

getAllProperties​

获取全部配置属性(含从项目组继承的属性)。

public Map<String, String> getAllProperties()

getProperty​

获取指定配置项。

public String getProperty(String key)

参数:

参数类型说明
keyString配置项名称,如 "odps.sql.type.system.odps2"

getExtendedProperties​

获取项目扩展属性。

public Map<String, String> getExtendedProperties()

getStorageTierInfo​

获取分层存储详情。需先调用 reload() 刷新数据。

public StorageTierInfo getStorageTierInfo()

StorageTierInfo 结构:

字段类型说明
storageTierString存储策略(STANDARD/LOWFREQUENCY/LONGTERM)
storageLastModifiedTimeDate最后统计时间
storageSizeMap<String, Long>各层级存储量(字节)

getSecurityManager​

获取项目安全管理器。

public SecurityManager getSecurityManager()

getDefaultQuotaNickname​

获取项目默认 Quota 的昵称。

public String getDefaultQuotaNickname()

返回值:String,默认 Quota 昵称


getDefaultQuotaRegion​

获取项目默认 Quota 的 Region。

public String getDefaultQuotaRegion()

返回值:String,默认 Quota 所属 Region


getTunnelEndpoint​

获取 Tunnel 接入点。

public String getTunnelEndpoint(String quotaName)

参数:

参数类型说明
quotaNameString计算配额名称,null 使用默认配额

getTunnelEndpoint(无参)​

获取项目的 Tunnel 端点地址。

public String getTunnelEndpoint() throws OdpsException

返回值:String,Tunnel 端点地址


getTenantId​

获取项目所属的租户 ID。

public String getTenantId()

返回值:String,租户 ID


isExternalCatalogBound​

判断项目是否绑定了外部 Catalog。

public boolean isExternalCatalogBound()

返回值:绑定了外部 Catalog 返回 true