def serialize_cluster(cluster_type, cid, cluster_object): """Serialize the cluster object. Replace also the linked Hadoop cluster if it exists. Args: cluster_type (str): The type of cluster to serialize. cid (int): The id of the cluster. cluster_object: The cluster to serialize. """ fname = __get_cluster_file(cluster_type, cid) logger.info("Serialize cluster (" + cluster_type + ") in " + fname) c_file = open(fname, 'wb') pickle.dump(cluster_object, c_file) if cluster_type != HadoopCluster.get_cluster_type(): hc_link_fname = __get_hc_link_file(cluster_type, cid) if os.path.exists(hc_link_fname): with open(hc_link_fname) as link_file: hc_id = int(link_file.readline()) serialize_cluster(HadoopCluster.get_cluster_type(), hc_id, cluster_object.hc)
def remove_cluster(cluster_type, cid): """Remove temporary files created for the given cluster. Remove the linked Hadoop cluster if it exists. Args: cluster_type (str): The type of cluster to serialize. cid (int): The id of the cluster. """ fname = __get_cluster_file(cluster_type, cid) os.remove(fname) if cluster_type != HadoopCluster.get_cluster_type(): hc_link_fname = __get_hc_link_file(cluster_type, cid) os.remove(hc_link_fname)