F #6063: Backup Jobs for OpenNebula

Includes the following changes:
- xml-schema for Backup Job and Scheduled Actions
- GO, Java api
- Deprecate onevm update-chart, delete-chart
    * The commands are replaced by sched-update and sched-delete
    * Refactor method deprecate_command, it's still possible to run the
    command
    * Delete 'shutdown' and 'delete' commands deprecated years ago
    * Fix --verbose option for sched-update and sched-delete
- Re-implementation of scheduled actions, now are managed and executed
  by oned
- Backup Job objects, API, and CLI commands
This commit is contained in:
Ruben S. Montero committed 2023-07-03 18:15:52 +02:00
1 parent 90585e42cf
commit 6bbfbb03e4
116 files changed
+8303 -2562

No files matched your search

@@ -0,0 +1,545 @@
/*******************************************************************************
* Copyright 2002-2023, OpenNebula Project, OpenNebula Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.opennebula.client.backupjob;
import org.opennebula.client.Client;
import org.opennebula.client.OneResponse;
import org.opennebula.client.PoolElement;
import org.w3c.dom.Node;
/**
* This class represents an OpenNebula Backup Job.
* It also offers static XML-RPC call wrappers.
*/
public class BackupJob extends PoolElement
{
private static final String METHOD_PREFIX = "backupjob.";
private static final String ALLOCATE = METHOD_PREFIX + "allocate";
private static final String DELETE = METHOD_PREFIX + "delete";
private static final String UPDATE = METHOD_PREFIX + "update";
private static final String RENAME = METHOD_PREFIX + "rename";
private static final String INFO = METHOD_PREFIX + "info";
private static final String CHOWN = METHOD_PREFIX + "chown";
private static final String CHMOD = METHOD_PREFIX + "chmod";
private static final String LOCK = METHOD_PREFIX + "lock";
private static final String UNLOCK = METHOD_PREFIX + "unlock";
private static final String BACKUP = METHOD_PREFIX + "backup";
private static final String CANCEL = METHOD_PREFIX + "cancel";
private static final String RETRY = METHOD_PREFIX + "retry";
private static final String PRIORITY = METHOD_PREFIX + "priority";
private static final String SCHEDADD = METHOD_PREFIX + "schedadd";
private static final String SCHEDDELETE = METHOD_PREFIX + "scheddelete";
private static final String SCHEDUPDATE = METHOD_PREFIX + "schedupdate";
/**
* Creates a new Backup Job representation.
* @param id The Backup Job id.
* @param client XML-RPC Client.
*/
public BackupJob(int id, Client client)
{
super(id, client);
}
/**
* @see PoolElement
*/
protected BackupJob(Node xmlElement, Client client)
{
super(xmlElement, client);
}
// =================================
// Static XML-RPC methods
// =================================
/**
* Allocates a new BackupJob in OpenNebula.
*
* @param client XML-RPC Client.
* @param description A string containing the template of the Backup Job.
*
* @return If successful the message contains the associated
* ID generated for this Backup Job.
*/
public static OneResponse allocate(
Client client,
String description)
{
return client.call(ALLOCATE, description);
}
/**
* Deletes an Backup Job from OpenNebula.
*
* @param client XML-RPC Client.
* @param id The Backup Job ID we want to delete.
* @return An encapsulated response.
*/
public static OneResponse delete(Client client, int id)
{
return client.call(DELETE, id);
}
/**
* Retrieves the information of the given Backup JOb.
*
* @param client XML-RPC Client.
* @param id The Backup Job ID
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse info(Client client, int id)
{
return client.call(INFO, id);
}
/**
* Replaces the template contents.
*
* @param client XML-RPC Client.
* @param id The Backkup Job ID we want to modify.
* @param new_template New template contents
* @return If successful the message contains the Backup Job ID.
*/
public static OneResponse update(Client client, int id, String new_template)
{
return client.call(UPDATE, id, new_template);
}
/**
* Renames Backup Job
*
* @param client XML-RPC Client.
* @param id The Backup Job ID.
* @param name New name for the Backup Job.
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse rename(Client client, int id, String name)
{
return client.call(RENAME, id, name);
}
/**
* Changes the owner/group
*
* @param client XML-RPC Client.
* @param id The Backup Job ID we want to modify.
* @param uid The new owner user ID. Set it to -1 to leave the current one.
* @param gid The new group ID. Set it to -1 to leave the current one.
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse chown(Client client, int id, int uid, int gid)
{
return client.call(CHOWN, id, uid, gid);
}
/**
* Changes the Backup Job permissions
*
* @param client XML-RPC Client.
* @param id The Backup Job ID we want to modify.
* @param owner_u 1 to allow, 0 deny, -1 do not change
* @param owner_m 1 to allow, 0 deny, -1 do not change
* @param owner_a 1 to allow, 0 deny, -1 do not change
* @param group_u 1 to allow, 0 deny, -1 do not change
* @param group_m 1 to allow, 0 deny, -1 do not change
* @param group_a 1 to allow, 0 deny, -1 do not change
* @param other_u 1 to allow, 0 deny, -1 do not change
* @param other_m 1 to allow, 0 deny, -1 do not change
* @param other_a 1 to allow, 0 deny, -1 do not change
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse chmod(Client client, int id,
int owner_u, int owner_m, int owner_a,
int group_u, int group_m, int group_a,
int other_u, int other_m, int other_a)
{
return chmod(client, CHMOD, id,
owner_u, owner_m, owner_a,
group_u, group_m, group_a,
other_u, other_m, other_a);
}
/**
* Changes the permissions
*
* @param client XML-RPC Client.
* @param id The Backup Job ID of the target object.
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse chmod(Client client, int id, String octet)
{
return chmod(client, CHMOD, id, octet);
}
/**
* Changes the permissions
*
* @param client XML-RPC Client.
* @param id The Backup Job ID of the target object.
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse chmod(Client client, int id, int octet)
{
return chmod(client, CHMOD, id, octet);
}
/**
* Lock Backup Job
*
* @param client XML-RPC Client.
* @param id The Backup Job ID.
* @param level Lock level.
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse lock(Client client, int id, int level)
{
return client.call(LOCK, id, level);
}
/**
* Unlock Backup Job
*
* @param client XML-RPC Client.
* @param id The Backup Job ID.
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse unlock(Client client, int id)
{
return client.call(UNLOCK, id);
}
/**
* Execute the Backup Job
*
* @param client XML-RPC Client.
* @param id The Backup Job ID.
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse backup(Client client, int id)
{
return client.call(BACKUP, id);
}
/**
* Cancel ongoing Backup Job
*
* @param client XML-RPC Client.
* @param id The Backup Job ID.
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse cancel(Client client, int id)
{
return client.call(CANCEL, id);
}
/**
* Retry failed Backup Job, executes again backup for failed Virtual Machines
*
* @param client XML-RPC Client.
* @param id The Backup Job ID.
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse retry(Client client, int id)
{
return client.call(RETRY, id);
}
/**
* Set priority for Backup Job, range for priority is 0-100.
* Base value is 50, only admin user can set priority over 50
*
* @param client XML-RPC Client.
* @param id The Backup Job ID.
* @param priority New value for priority
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse priority(Client client, int id, int prio)
{
return client.call(PRIORITY, id, prio);
}
/**
* Add Scheduled Action to Backup Job
*
* @param client XML-RPC Client.
* @param id The Backup Job ID.
* @param template Scheduled Action template.
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse schedadd(Client client, int id, String template)
{
return client.call(SCHEDADD, id, template);
}
/**
* Update Backup Job Scheduled Action
*
* @param client XML-RPC Client.
* @param id The Backup Job ID.
* @param sa_id The Scheduled Action ID.
* @param template Updated values for Scheduled Action.
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse schedupdate(Client client, int id, int sa_id, String template)
{
return client.call(SCHEDUPDATE, id, sa_id, template);
}
/**
* Delete Backup Job Scheduled Action
*
* @param client XML-RPC Client.
* @param id The Backup Job ID.
* @param sa_id The Scheduled Action ID.
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse scheddelete(Client client, int id, int sa_id)
{
return client.call(SCHEDDELETE, id, sa_id);
}
// =================================
// Instanced object XML-RPC methods
// =================================
/**
* Retrieves the information of the Backup Job.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse info()
{
OneResponse response = info(client, id);
super.processInfo(response);
return response;
}
/**
* Deletes the Backup Job from OpenNebula.
*
* @param force Ignore errors
* @return A encapsulated response.
*/
public OneResponse delete()
{
return delete(client, id);
}
/**
* Replaces the template contents.
*
* @param new_template New template contents
* @return If successful the message contains the Backup Job ID.
*/
public OneResponse update(String new_template)
{
return update(client, id, new_template);
}
/**
* Renames this Backup Job
*
* @param name New name for the Backup Job.
* @return If an error occurs the error message contains the reason.
*/
public OneResponse rename(String name)
{
return rename(client, id, name);
}
/**
* Changes the owner/group
*
* @param uid The new owner user ID. Set it to -1 to leave the current one.
* @param gid The new group ID. Set it to -1 to leave the current one.
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chown(int uid, int gid)
{
return chown(client, id, uid, gid);
}
/**
* Changes the owner
*
* @param uid The new owner user ID.
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chown(int uid)
{
return chown(uid, -1);
}
/**
* Changes the group
*
* @param gid The new group ID.
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chgrp(int gid)
{
return chown(-1, gid);
}
/**
* Changes the Backup Job permissions
*
* @param owner_u 1 to allow, 0 deny, -1 do not change
* @param owner_m 1 to allow, 0 deny, -1 do not change
* @param owner_a 1 to allow, 0 deny, -1 do not change
* @param group_u 1 to allow, 0 deny, -1 do not change
* @param group_m 1 to allow, 0 deny, -1 do not change
* @param group_a 1 to allow, 0 deny, -1 do not change
* @param other_u 1 to allow, 0 deny, -1 do not change
* @param other_m 1 to allow, 0 deny, -1 do not change
* @param other_a 1 to allow, 0 deny, -1 do not change
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chmod(int owner_u, int owner_m, int owner_a,
int group_u, int group_m, int group_a,
int other_u, int other_m, int other_a)
{
return chmod(client, id,
owner_u, owner_m, owner_a,
group_u, group_m, group_a,
other_u, other_m, other_a);
}
/**
* Changes the permissions
*
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chmod(String octet)
{
return chmod(client, id, octet);
}
/**
* Changes the permissions
*
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chmod(int octet)
{
return chmod(client, id, octet);
}
/**
* Lock this Backup Job
*
* @param level Lock level.
* @return If an error occurs the error message contains the reason.
*/
public OneResponse lock(int level)
{
return lock(client, id, level);
}
/**
* Unlock this Backup Job
*
* @return If an error occurs the error message contains the reason.
*/
public OneResponse unlock()
{
return unlock(client, id);
}
/**
* Execute the Backup Job
*
* @return If an error occurs the error message contains the reason.
*/
public OneResponse backup()
{
return backup(client, id);
}
/**
* Cancel ongoing Backup Job
*
* @return If an error occurs the error message contains the reason.
*/
public OneResponse cancel()
{
return cancel(client, id);
}
/**
* Retry failed Backup Job, executes again backup for failed Virtual Machines
*
* @return If an error occurs the error message contains the reason.
*/
public OneResponse retry()
{
return retry(client, id);
}
/**
* Set priority for Backup Job, range for priority is 0-100.
* Base value is 50, only admin user can set priority over 50
*
* @param priority New value for priority
* @return If an error occurs the error message contains the reason.
*/
public OneResponse priority(int prio)
{
return priority(client, id, prio);
}
/**
* Add Scheduled Action to Backup Job
*
* @param template Scheduled Action template.
* @return If an error occurs the error message contains the reason.
*/
public OneResponse schedadd(String template)
{
return schedadd(client, id, template);
}
/**
* Update Backup Job Scheduled Action
*
* @param sa_id The Scheduled Action ID.
* @param template Updated values for Scheduled Action.
* @return If an error occurs the error message contains the reason.
*/
public OneResponse schedupdate(int sa_id, String template)
{
return schedupdate(client, id, sa_id, template);
}
/**
* Delete Backup Job Scheduled Action
*
* @param sa_id The Scheduled Action ID.
* @return If an error occurs the error message contains the reason.
*/
public OneResponse scheddelete(int sa_id)
{
return scheddelete(client, id, sa_id);
}
}
@@ -0,0 +1,267 @@
/*******************************************************************************
* Copyright 2002-2023, OpenNebula Project, OpenNebula Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.opennebula.client.backupjob;
import java.util.AbstractList;
import java.util.Iterator;
import org.opennebula.client.Client;
import org.opennebula.client.OneResponse;
import org.opennebula.client.Pool;
import org.opennebula.client.PoolElement;
import org.w3c.dom.Node;
/**
* This class represents an OpenNebula Backup Job pool.
* It also offers static XML-RPC call wrappers.
*/
public class BackupJobPool extends Pool implements Iterable<BackupJob>
{
private static final String ELEMENT_NAME = "BACKUPJOB";
private static final String INFO_METHOD = "backupjobpool.info";
private int filter;
/**
* Creates a new Backup Job pool with the default filter flag value
* set to {@link Pool#MINE_GROUP} (Backup Jobs belonging to the connected user,
* and the ones in his group)
*
* @param client XML-RPC Client.
*
* @see BackupJobPool#BackupJobPool(Client, int)
*/
public BackupJobPool(Client client)
{
super(ELEMENT_NAME, client, INFO_METHOD);
this.filter = MINE_GROUP;
}
/**
* Creates a new Backup Job pool.
*
* @param client XML-RPC Client.
* @param filter Filter flag to use by default in the method
* {@link BackupJobPool#info()}. Possible values:
* <ul>
* <li>{@link Pool#ALL}: All Backup Jobs</li>
* <li>{@link Pool#MINE}: Connected user's Backup Jobs</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Backup Jobs, and the ones in
* his group</li>
* <li>{@link Pool#GROUP}: User's primary group Backup Jobs</li>
* <li>&gt;= 0 UID User's Backup Jobs</li>
* </ul>
*/
public BackupJobPool(Client client, int filter)
{
super(ELEMENT_NAME, client, INFO_METHOD);
this.filter = filter;
}
/* (non-Javadoc)
* @see org.opennebula.client.Pool#factory(org.w3c.dom.Node)
*/
@Override
public PoolElement factory(Node node)
{
return new BackupJob(node, client);
}
/**
* Retrieves all or part of the Backup Jobs in the pool.
*
* @param client XML-RPC Client.
* @param filter Filter flag to use. Possible values:
* <ul>
* <li>{@link Pool#ALL}: All Backup JObs</li>
* <li>{@link Pool#MINE}: Connected user's Backup Jobs</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Backup Jobs, and the ones in
* his group</li>
* <li>{@link Pool#GROUP}: User's primary group Backup Jobs</li>
* <li>&gt;= 0 UID User's Backup Jobs</li>
* </ul>
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse info(Client client, int filter)
{
return Pool.info(client, INFO_METHOD, filter, -1, -1);
}
/**
* Retrieves all the Backup Jobs in the pool.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse infoAll(Client client)
{
return Pool.infoAll(client, INFO_METHOD);
}
/**
* Retrieves all the connected user's Backup Jobs.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse infoMine(Client client)
{
return Pool.infoMine(client, INFO_METHOD);
}
/**
* Retrieves all the connected user's Backup Jobs and the ones in
* his group.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse infoGroup(Client client)
{
return Pool.infoGroup(client, INFO_METHOD);
}
/**
* Retrieves all or part of the Backup Jobs in the pool. The Backup Jobs to retrieve
* can be also filtered by Id, specifying the first and last Id to include.
*
* @param client XML-RPC Client.
* @param filter Filter flag to use. Possible values:
* <ul>
* <li>{@link Pool#ALL}: All Backup Jobs</li>
* <li>{@link Pool#MINE}: Connected user's Backup Jobs</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Backup Jobs, and the ones in
* his group</li>
* <li>{@link Pool#GROUP}: User's primary group Backup Jobs</li>
* <li>&gt;= 0 UID User's Backup Jobs</li>
* </ul>
* @param startId Lowest ID to retrieve
* @param endId Biggest ID to retrieve
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse info(Client client, int filter,
int startId, int endId)
{
return Pool.info(client, INFO_METHOD, filter, startId, endId);
}
/**
* Loads the xml representation of all or part of the
* Backup Jobs in the pool. The filter used is the one set in
* the constructor.
*
* @see BackupJobPool#info(Client, int)
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse info()
{
return super.info(filter, -1, -1);
}
/**
* Loads the xml representation of all the Backup Jobs in the pool.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse infoAll()
{
return super.infoAll();
}
/**
* Loads the xml representation of all the connected user's Backup Jobs.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse infoMine()
{
return super.infoMine();
}
/**
* Loads the xml representation of all the connected user's Backup Jobs and
* the ones in his group.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse infoGroup()
{
return super.infoGroup();
}
/**
* Retrieves all or part of the Backup Jobs in the pool. The Backup Jobs to retrieve
* can be also filtered by Id, specifying the first and last Id to include.
*
* @param filter Filter flag to use. Possible values:
* <ul>
* <li>{@link Pool#ALL}: All Backup Jobs</li>
* <li>{@link Pool#MINE}: Connected user's Backup Jobs</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Backup Jobs, and the ones in
* his group</li>
* <li>{@link Pool#GROUP}: User's primary group Backup Jobs</li>
* <li>&gt;= 0 UID User's Backup Jobs</li>
* </ul>
* @param startId Lowest ID to retrieve
* @param endId Biggest ID to retrieve
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse info(int filter, int startId, int endId)
{
return super.info(filter, startId, endId);
}
public Iterator<BackupJob> iterator()
{
AbstractList<BackupJob> ab = new AbstractList<BackupJob>()
{
public int size()
{
return getLength();
}
public BackupJob get(int index)
{
return (BackupJob) item(index);
}
};
return ab.iterator();
}
/**
* Returns the Backup Job with the given Id from the pool. If it is not found,
* then returns null. The method {@link #info()} must be called before.
*
* @param id of the Backup Job to retrieve
* @return The Backup Job with the given Id, or null if it was not found.
*/
public BackupJob getById(int id)
{
return (BackupJob) super.getById(id);
}
}