Skip to content

Commit

Permalink
Origin/apis gettickets (#82)
Browse files Browse the repository at this point in the history
*retrieve created tickets for HPE integration
  • Loading branch information
vinutha17 authored and sdandam committed Jul 23, 2019
1 parent 4762bde commit 3ca1fe8
Show file tree
Hide file tree
Showing 11 changed files with 367 additions and 19 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ fn main() {
customize: protobuf_codegen_pure::Customize {
..Default::default()
},
}).expect("protoc");
})
.expect("protoc");
}
15 changes: 15 additions & 0 deletions api/protos/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ message OpStringResult {
optional string error_msg = 3;
}

message JiraInfo{
required string ticket_id = 1;
required string server_name = 2;
}

message OpJiraTicketsResult {
required ResultType result = 1;
// Values is set if OK
repeated JiraInfo tickets = 2;
// error_msg is set if ERR
optional string error_msg = 3;
}

enum Op {
// Generic Add Disk. Returns OpResult
Add = 1;
Expand All @@ -101,6 +114,8 @@ enum Op {
Remove = 4;
// Returns bool
SafeToRemove = 5;
//return tickets created
GetCreatedTickets = 7;
}

// Datacenter related API's
Expand Down
3 changes: 1 addition & 2 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ pub mod gluster;
use std::path::Path;
use std::str::FromStr;


use serde_derive::*;
use self::ceph::CephBackend;
use self::gluster::GlusterBackend;
use helpers::error::*;
use serde_derive::*;

/// Different distributed storage clusters have different ways of adding and removing
/// disks. This will be consolidated here in trait impl's.
Expand Down
18 changes: 17 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/// This is built into a separate binary called bynar-client
//mod disk_manager;
use std::fs::{read_to_string, File};
use std::path::Path;
use std::str::FromStr;

//use disk_manager::disk_manager;
use api::service::Disk;
use clap::{crate_authors, crate_version, App, Arg, ArgMatches, SubCommand};
use helpers::error::BynarResult;
use hostname::get_hostname;
use log::{error, info};
use log::{error, info,trace};
use simplelog::{CombinedLogger, Config, TermLogger, WriteLogger};
use zmq::Socket;
/*
Expand Down Expand Up @@ -64,6 +66,16 @@ fn handle_list_disks(s: &mut Socket) {
};
}

fn handle_jira_tickets(s: &mut Socket) -> BynarResult<()>{
trace!("handle_jira_tickets called");
let tickets = helpers::get_jira_tickets(s)?;
trace!("handle_jira_tickets Finished");
Ok(())


}


fn handle_remove_disk(s: &mut Socket, matches: &ArgMatches<'_>) {
let p = Path::new(matches.value_of("path").unwrap());
info!("Removing disk: {}", p.display());
Expand Down Expand Up @@ -145,6 +157,7 @@ fn get_cli_args(default_server_key: &str) -> ArgMatches<'_> {
),
)
.subcommand(SubCommand::with_name("list").about("List all disks on a server"))
.subcommand(SubCommand::with_name("get_jira_tickets").about("get all tickets created"))
.subcommand(
SubCommand::with_name("remove")
.about("Remove a disk from the cluster")
Expand Down Expand Up @@ -224,4 +237,7 @@ fn main() {
if let Some(ref matches) = matches.subcommand_matches("remove") {
handle_remove_disk(&mut s, matches);
}
if let Some(ref matches) = matches.subcommand_matches("get_jira_tickets") {
handle_jira_tickets(&mut s);
}
}
68 changes: 65 additions & 3 deletions src/disk_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ use std::thread;
use std::time::Duration;

use api::service::{
Disk, DiskType, Disks, Op, OpBoolResult, OpResult, Partition, PartitionInfo, ResultType,
Disk, DiskType, Disks, JiraInfo, Op, OpBoolResult, OpJiraTicketsResult, OpResult, Partition,
PartitionInfo, ResultType,
};
mod backend;
mod in_progress;
mod test_disk;

use crate::backend::BackendType;
use crate::in_progress::create_db_connection_pool;
use block_utils::{Device, MediaType};
use clap::{crate_authors, crate_version, App, Arg};
use gpt::{disk, header::read_header, partition::read_partitions};
use hashicorp_vault::client::VaultClient;
use helpers::error::*;
use helpers::{error::*, host_information::Host, ConfigSettings};
use hostname::get_hostname;
use log::{debug, error, info, trace, warn};
use protobuf::parse_from_bytes;
Expand Down Expand Up @@ -224,12 +229,22 @@ fn listen(
}
};
}
Op::GetCreatedTickets => {
match get_jira_tickets(&mut responder,config_dir) {
Ok(_) => {
info!("Fetching jira tickets finished");
}
Err(e) => {
error!("Fetching jira error: {:?}", e);
}
};
}
};
thread::sleep(Duration::from_millis(10));
}
}

fn respond_to_client(result: &OpResult, s: &mut Socket) -> BynarResult<()> {
fn respond_to_client<T: protobuf::Message>(result: &T, s: &mut Socket) -> BynarResult<()> {
let encoded = result.write_to_bytes()?;
let msg = Message::from_slice(&encoded)?;
debug!("Responding to client with msg len: {}", msg.len());
Expand Down Expand Up @@ -411,6 +426,53 @@ fn safe_to_remove_disk(
Ok(())
}

pub fn get_jira_tickets(s: &mut Socket, config_dir: &Path) -> BynarResult<()> {
let mut result = OpJiraTicketsResult::new();
let config: ConfigSettings = match helpers::load_config(&config_dir, "bynar.json") {
Ok(p) => p,
Err(e) => {
error!("Failed to load config file {}", e);
result.set_result(ResultType::ERR);
result.set_error_msg(e.to_string());

// unable to load config file
let _ = respond_to_client(&result, s);
return Ok(());
}
};
let db_config = config.database;
let db_pool = match in_progress::create_db_connection_pool(&db_config) {
Ok(p) => p,
Err(e) => {
error!("Failed to create database pool {}", e);
result.set_result(ResultType::ERR);
result.set_error_msg(e.to_string());

// unable to create DB connection
let _ = respond_to_client(&result, s);
return Ok(());
}
};

info!("Getting all pending repair tickets");
let tickets = in_progress::get_all_pending_tickets(&db_pool)?;
debug!("outstanding tickets: {:?}", tickets);
result.set_result(ResultType::OK);
let proto_jira: Vec<JiraInfo> = tickets
.iter()
.map(|j| {
let mut jira_result = JiraInfo::new();
jira_result.set_ticket_id(j.ticket_id.clone());
let host_name = in_progress::get_host_name(&db_pool,j.device_id);
jira_result.set_server_name(host_name.unwrap().unwrap());
jira_result
})
.collect();
result.set_tickets(RepeatedField::from_vec(proto_jira));
let _ = respond_to_client(&result, s);
Ok(())
}

fn main() {
let matches = App::new("Disk Manager")
.version(crate_version!())
Expand Down
Loading

0 comments on commit 3ca1fe8

Please sign in to comment.